diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-11-10 20:44:44 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-11-10 20:44:44 -0500 |
commit | 0c4188f6d76fad021a93eb1012630c717bda80a1 (patch) | |
tree | cf750ce90574fa55b066de623c0ce42005a26545 /src/stdlib/atoi.c | |
parent | 3ed8c9f2df0b5f0bfe1006037c46d4f32ec6ca7b (diff) | |
download | musl-0c4188f6d76fad021a93eb1012630c717bda80a1.tar.gz musl-0c4188f6d76fad021a93eb1012630c717bda80a1.tar.bz2 musl-0c4188f6d76fad021a93eb1012630c717bda80a1.tar.xz musl-0c4188f6d76fad021a93eb1012630c717bda80a1.zip |
fix signed overflows at most-negative values in ato(i|l|ll)
patch by Pascal Cuoq (with minor tweaks to comments)
Diffstat (limited to 'src/stdlib/atoi.c')
-rw-r--r-- | src/stdlib/atoi.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c index 648b154f..9baca7b8 100644 --- a/src/stdlib/atoi.c +++ b/src/stdlib/atoi.c @@ -9,7 +9,8 @@ int atoi(const char *s) case '-': neg=1; case '+': s++; } + /* Compute n as a negative number to avoid overflow on INT_MIN */ while (isdigit(*s)) - n = 10*n + *s++ - '0'; - return neg ? -n : n; + n = 10*n - (*s++ - '0'); + return neg ? n : -n; } |