At that point, result is a multiple of 10, so it can at most be
2147483640, i.e. (INT_MAX / 10)*10.
If it's less than that, you can add any value between 0 and 9 to it and
it won't overflow.
If it's *equal* to that, you can only add a value between 0 and 7
without overflowing, i.e. the maximum is INT_MAX % 10.
Addresses Coverity CID
1400557.
too_large = 1;
} else {
result *= 10;
- if (result == INT_MAX && c > (INT_MAX % 10)) {
+ if (result == ((INT_MAX / 10) * 10) && c > (INT_MAX % 10)) {
/* This will overflow an int when we add c */
too_large = 1;
} else