Skip to content

Commit

Permalink
Set maximum digit length to 9
Browse files Browse the repository at this point in the history
The type of calc->stack[0] is int,
and the maximum value for an int is 2,147,483,647.
Conservatively, we ensure that when the length reaches 9 digits,
pressing the digit button will not increase the number of digits.
  • Loading branch information
Bennctu committed Aug 21, 2024
1 parent d36535c commit 39c53a0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ static void _apps_calc_digit(apps_calc_t *calc, int digit)
calc->stack[0] = 0;
calc->pending_delete = false;
}
calc->stack[0] = calc->stack[0] * 10 + digit;
_apps_calc_update_value(calc);

if (calc->stack[0] < 100000000) {
calc->stack[0] = calc->stack[0] * 10 + digit;
_apps_calc_update_value(calc);
}
}

static void _apps_calc_button_signal(twin_button_t *button,
Expand Down

0 comments on commit 39c53a0

Please sign in to comment.