Skip to content

Commit

Permalink
calc: Set maximum digit length to 9 (#35)
Browse files Browse the repository at this point in the history
The type of calc->stack[0] is an integer, and the maximum value for an
int is 2147483647. To ensure safety, when the length reaches 9 digits,
pressing the digit button will not increase the number of digits.

Close #25
  • Loading branch information
Bennctu authored Aug 22, 2024
1 parent d36535c commit fd3e451
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ static void _apps_calc_digit(apps_calc_t *calc, int digit)
calc->stack[0] = 0;
calc->pending_delete = false;
}

/* When the length reaches 9 digits, pressing the digit button will not
* increase the number of digits. */
if (calc->stack[0] > 99999999)
return;

calc->stack[0] = calc->stack[0] * 10 + digit;
_apps_calc_update_value(calc);
}
Expand Down

0 comments on commit fd3e451

Please sign in to comment.