Skip to content

Commit

Permalink
calc: 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.
Close #25
  • Loading branch information
Bennctu committed Aug 22, 2024
1 parent d36535c commit 8bc23c0
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 8bc23c0

Please sign in to comment.