X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdlib%2Fatol.c;h=140ea3ea3fa27ce690bd61d8a7520efa28e3aad1;hb=90f770523f54b2e63a6ad46cba0149c9dc01ddd4;hp=9c91bba9d915dbe1760918f7af76ab548b324717;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl 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; }