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 <[email protected]> Cc: Bruno Haible <[email protected]> Cc: Đoàn Trần Công 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 != 0) + else if (errno == ERANGE) { - if (errno != ERANGE) - return LONGINT_INVALID; err = LONGINT_OVERFLOW; } -- 2.45.2
signature.asc
Description: PGP signature
