changeset 1792:d68e41b0a355

(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.
author Jim Meyering <jim@meyering.net>
date Tue, 20 Apr 1999 13:24:14 +0000
parents 1fd4a36cb722
children 0f2f1e451293
files lib/xstrtoumax.c
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/xstrtoumax.c
+++ b/lib/xstrtoumax.c
@@ -78,12 +78,12 @@
     /* 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)