From: Alejandro Colomar <alx@kernel.org>
To: bug-gnulib@gnu.org
Cc: "Alejandro Colomar" <alx@kernel.org>,
"Paul Eggert" <eggert@cs.ucla.edu>,
"Bruno Haible" <bruno@clisp.org>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"Eli Schwartz" <eschwartz93@gmail.com>,
"Sam James" <sam@gentoo.org>, "Serge Hallyn" <serge@hallyn.com>,
"Iker Pedrosa" <ipedrosa@redhat.com>,
"Andrew J. Hesford" <ajh@sideband.org>,
"Michael Vetter" <jubalh@iodoru.org>,
liba2i@lists.linux.dev
Subject: [PATCH v1] xstrtol: Remove dead code
Date: Thu, 18 Jul 2024 22:33:07 +0200 [thread overview]
Message-ID: <20240718203147.47143-2-alx@kernel.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 2117 bytes --]
strtol(3) has a limited set of possible states:
- The base was invalid.
- return 0
- errno = EINVAL
- endp is not set
We cover this case with the assure() call, before strtol(3).
- No conversion was performed.
- return 0
- errno may be EINVAL, or may be unset.
- *endp == s
We cover this case with the 'if (*p == s)' check.
- Conversion performed with extra trailing characters.
- return any number
- errno is not set
- *endp != s
- **endp != '\0'
We let this fall through.
- String fully converted.
- return any number
- errno is not set
- *endp != s
- **endp == '\0'
We let this fall through.
- Overflow
- return LONG_MAX or LONG_MIN
- errno = ERANGE
- *endp != s
We cover this with 'else if (errno != 0)'
The condition '*endp != s && errno != 0 && errno != ERANGE' is
unreachable. The only errno possible if '*endp != s' is ERANGE.
Fixes: 790855e18a1d (2003-10-14, "Handle invalid suffixes and overflow independently, so that ...")
Cc: Paul Eggert <eggert@cs.ucla.edu>
Cc: Bruno Haible <bruno@clisp.org>
Cc: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Cc: Eli Schwartz <eschwartz93@gmail.com>
Cc: Sam James <sam@gentoo.org>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Andrew J. Hesford" <ajh@sideband.org>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: <liba2i@lists.linux.dev>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Range-diff against v0:
-: ---------- > 1: 1af702673f xstrtol: Remove dead code
lib/xstrtol.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/lib/xstrtol.c b/lib/xstrtol.c
index 575c16d45f..5d10ce041e 100644
--- a/lib/xstrtol.c
+++ b/lib/xstrtol.c
@@ -110,10 +110,8 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
else
return LONGINT_INVALID;
}
- else if (errno != 0)
+ else if (errno == ERANGE)
{
- if (errno != ERANGE)
- return LONGINT_INVALID;
err = LONGINT_OVERFLOW;
}
--
2.45.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2024-07-18 20:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 20:33 Alejandro Colomar [this message]
2024-07-18 21:09 ` [PATCH v1] xstrtol: Remove dead code Bruno Haible
2024-07-18 21:25 ` Alejandro Colomar
2024-07-18 21:33 ` Andrew J. Hesford
2024-07-18 22:14 ` Alejandro Colomar
2024-07-18 23:32 ` Alejandro Colomar
2024-07-19 17:13 ` Bruno Haible
2024-07-18 22:34 ` Bruno Haible
2024-07-18 23:21 ` Alejandro Colomar
2024-07-19 16:54 ` Bruno Haible
2024-07-19 18:15 ` Alejandro Colomar
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=20240718203147.47143-2-alx@kernel.org \
--to=alx@kernel.org \
--cc=ajh@sideband.org \
--cc=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=congdanhqx@gmail.com \
--cc=eggert@cs.ucla.edu \
--cc=eschwartz93@gmail.com \
--cc=ipedrosa@redhat.com \
--cc=jubalh@iodoru.org \
--cc=liba2i@lists.linux.dev \
--cc=sam@gentoo.org \
--cc=serge@hallyn.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.