summaryrefslogtreecommitdiff
path: root/lib/xstrtoumax.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-04-20 13:24:14 +0000
committerJim Meyering <jim@meyering.net>1999-04-20 13:24:14 +0000
commit154588d7229910ae7d401a3f20433108695dae02 (patch)
tree8638ec3db128d0b4cfa5ced0a0cfa196af8be978 /lib/xstrtoumax.c
parentf9270b650fec1542d87842c5f3f570c5982a5869 (diff)
downloadcoreutils-154588d7229910ae7d401a3f20433108695dae02.tar.xz
(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.
Diffstat (limited to 'lib/xstrtoumax.c')
-rw-r--r--lib/xstrtoumax.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/xstrtoumax.c b/lib/xstrtoumax.c
index 40f0d783a..9ef799b34 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)