Skip to content

Commit fd3e451

Browse files
authored
calc: Set maximum digit length to 9 (#35)
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
1 parent d36535c commit fd3e451

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

apps/calc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ static void _apps_calc_digit(apps_calc_t *calc, int digit)
119119
calc->stack[0] = 0;
120120
calc->pending_delete = false;
121121
}
122+
123+
/* When the length reaches 9 digits, pressing the digit button will not
124+
* increase the number of digits. */
125+
if (calc->stack[0] > 99999999)
126+
return;
127+
122128
calc->stack[0] = calc->stack[0] * 10 + digit;
123129
_apps_calc_update_value(calc);
124130
}

0 commit comments

Comments
 (0)