[PATCH v1] xstrtol: Remove dead code

Alejandro Colomar <[email protected]> Thu, 18 Jul 2024 22:33:07 +0200
Newsgroups dev.linux.lists.liba2i
Message-ID <[email protected]>
--rku3rthl3h6bslbx
Content-Type: text/plain; protected-headers=v1; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
From: Alejandro Colomar <[email protected]>
To: [email protected]
Cc: Alejandro Colomar <[email protected]>, Paul Eggert <[email protected]>, 
	Bruno Haible <[email protected]>, 
	=?utf-8?B?xJBvw6BuIFRy4bqnbiBDw7RuZw==?= Danh <[email protected]>, Eli Schwartz <[email protected]>, Sam James <[email protected]>, 
	Serge Hallyn <[email protected]>, Iker Pedrosa <[email protected]>, 
	"Andrew J. Hesford" <[email protected]>, Michael Vetter <[email protected]>, [email protected]
Subject: [PATCH v1] xstrtol: Remove dead code
MIME-Version: 1.0

strtol(3) has a limited set of possible states:

-  The base was invalid.
   -  return 0
   -  errno =3D 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 =3D=3D s
   We cover this case with the 'if (*p =3D=3D s)' check.

-  Conversion performed with extra trailing characters.
   -  return any number
   -  errno is not set
   -  *endp !=3D s
   -  **endp !=3D '\0'
   We let this fall through.

-  String fully converted.
   -  return any number
   -  errno is not set
   -  *endp !=3D s
   -  **endp =3D=3D '\0'
   We let this fall through.

-  Overflow
   -  return LONG_MAX or LONG_MIN
   -  errno =3D ERANGE
   -  *endp !=3D s
   We cover this with 'else if (errno !=3D 0)'

The condition '*endp !=3D s && errno !=3D 0 && errno !=3D ERANGE' is
unreachable.  The only errno possible if '*endp !=3D s' is ERANGE.

Fixes: 790855e18a1d (2003-10-14, "Handle invalid suffixes and overflow inde=
pendently, so that ...")
Cc: Paul Eggert <[email protected]>
Cc: Bruno Haible <[email protected]>
Cc: =C4=90o=C3=A0n Tr=E1=BA=A7n C=C3=B4ng Danh <[email protected]>
Cc: Eli Schwartz <[email protected]>
Cc: Sam James <[email protected]>
Cc: Serge Hallyn <[email protected]>
Cc: Iker Pedrosa <[email protected]>
Cc: "Andrew J. Hesford" <[email protected]>
Cc: Michael Vetter <[email protected]>
Cc: <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
---
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 !=3D 0)
+  else if (errno =3D=3D ERANGE)
     {
-      if (errno !=3D ERANGE)
-        return LONGINT_INVALID;
       err =3D LONGINT_OVERFLOW;
     }
=20
--=20
2.45.2


--rku3rthl3h6bslbx
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmaZfAMACgkQnowa+77/
2zKFXA//V9Pb2Tckq6ohgqikjBFzxmp501nGDLlKjfLcMwXYv9VP4O1ZtjmbPLJ8
/WY7e4SAYl2LAWvoh7dwZaj1Lcs0fFZmLJoU8D+dCotAcp7hZGLgaeuyZ3ApWYYh
wRR5gkHwJ2W/SarFsP2gOz1QH6+Ae4066OTL7U86auuEw9NSVwtnP0XfrAuFtVym
EZ4DoVDFLxv0GnbpiI7mWpHhsEKSk/5CnlQ1LelmqYGmBPs9HfZeZ+MC/lnG38EQ
QZeddkw7hUXt5akxQHaMZ82M6kJGQ01eDqKom6pt0a6NdRu+2hBWsoCJ+uvq+CRa
8KgP+Kd+t2YnD+DvAxBrbwIaEeOxzKc6OGExa9ZXyc5azCXJ76DAZtVtKUCerqaO
EzaZDtL6LfNQ68O8qiB7SYkI1Bci1n5y1TxmGJUDoq4WMwJWPktYPzuiUwx+P4tP
p5BDHqLxeCgt06MIk/R0gqpEWNhBlf2hT0bulyE6Ja6VwWVOvm0eI7Uh4srgPPiB
EIdhPBOH03vXdWSPqLlyqKBagxq8oHI/u9Y6Cd/eI2AZzQ6VGAEoFdxD2Bj5FcOn
xZdvjHcw8mhsZlo6t+cBH+pC29QZdO92+HaxgEDOpS3lu1Dezq/rM3ADOxtpzgBH
fwj2Qulok46raNy9ZTZChf7Gwa66LcWuprfghqVR6KNsuCTtkZw=
=mLcn
-----END PGP SIGNATURE-----

--rku3rthl3h6bslbx--