diff options
Diffstat (limited to 'src/stdlib/atol.c')
-rw-r--r-- | src/stdlib/atol.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/stdlib/atol.c b/src/stdlib/atol.c index 9c91bba9..140ea3ea 100644 --- a/src/stdlib/atol.c +++ b/src/stdlib/atol.c @@ -10,7 +10,8 @@ long atol(const char *s) case '-': neg=1; case '+': s++; } + /* Compute n as a negative number to avoid overflow on LONG_MIN */ while (isdigit(*s)) - n = 10*n + *s++ - '0'; - return neg ? -n : n; + n = 10*n - (*s++ - '0'); + return neg ? n : -n; } |