[PATCH] mystring: Ignore ERANGE errors in atomax
Herbert Xu <[email protected]> Sun, 14 Sep 2025 09:37:51 +0800
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
Szász Gergely <[email protected]> wrote: > Hello, > > $ dash > $ echo $((0x8000000000000000)) > 9223372036854775807 > $ printf %x\\n $((0x8000000000000000)) > 7fffffffffffffff > $ printf "%x %x\n" $((0x8000000000000000)) $((0x8000000000000000-1)) > 7fffffffffffffff 7ffffffffffffffe > $ echo $((-9223372036854775808)) > -9223372036854775807 > $ x=0x8000000000000000 > $ echo $((x)) > dash: 6: Illegal number: 0x8000000000000000 > $ exit So the only inconsistency here is that $((x)) does a range check while the others don't. I looked into the history and the range check came from the built-in test(1) utility. In that case other shells (ksh93) don't necessarily do a range check. So I've decided to simply remove the range check for consistency. ---8<--- Remove ERANGE check in atomax for consistency as other direct calls to strtoimax do not perform the range check. Reported-by: Szász Gergely <[email protected]> Signed-off-by: Herbert Xu <[email protected]> diff --git a/src/mystring.c b/src/mystring.c index ca0cd39..97e240c 100644 --- a/src/mystring.c +++ b/src/mystring.c @@ -129,9 +129,6 @@ intmax_t atomax(const char *s, int base) errno = 0; r = strtoimax(s, &p, base); - if (errno == ERANGE) - badnum(s); - /* * Disallow completely blank strings in non-arithmetic (base != 0) * contexts. -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt