From: Jim Meyering Date: Tue, 20 Apr 1999 13:24:14 +0000 (+0000) Subject: (my_strtoumax): Fix typo in computing X-Git-Tag: FILEUTILS-4_0g~19 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=93627d90a57bd8190dc5adc94685b7e2d96d9312;p=gnulib.git (my_strtoumax): Fix typo in computing whether overflow occurred. Improve overflow-detection to use only one conditional branch total, rather than 2N+1 conditional branches for an N-digit number. --- diff --git a/lib/xstrtoumax.c b/lib/xstrtoumax.c index 40f0d783ac..9ef799b341 100644 --- a/lib/xstrtoumax.c +++ b/lib/xstrtoumax.c @@ -78,12 +78,12 @@ my_strtoumax (char const *ptr, char **endptr, int base) /* An implementation with uintmax_t longer than long, but with no known way to convert it. Do it by hand. Assume base 10. */ uintmax_t n = 0; - int overflow = 0; + uintmax_t overflow = 0; for (; '0' <= *ptr && *ptr <= '9'; ptr++) { uintmax_t n10 = n * 10; int digit = *ptr - '0'; - overflow |= ! (n10 / 10 == n && n10 < n10 + digit); + overflow |= n ^ (n10 + digit) / 10; n = n10 + digit; } if (endptr)