From: Herbert Xu <herbert@gondor.apana.org.au>
To: "Szász Gergely" <szaszg@hu.inter.net>
Cc: dash@vger.kernel.org
Subject: [PATCH] mystring: Ignore ERANGE errors in atomax
Date: Sun, 14 Sep 2025 09:37:51 +0800 [thread overview]
Message-ID: <aMYcb8Bd7BrZEMoR@gondor.apana.org.au> (raw)
In-Reply-To: <20250213160055.ymjwvpbwsgpvif3p@stanc>
Szász Gergely <szaszg@hu.inter.net> 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 <szaszg@hu.inter.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
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 <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2025-09-14 1:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 16:00 bug: 64bit arithmetic/number parsing Szász Gergely
2025-09-14 1:37 ` Herbert Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aMYcb8Bd7BrZEMoR@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=szaszg@hu.inter.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox