bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)


From: Paul Eggert
Subject: Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)
Date: Wed, 24 Jul 2024 13:11:33 -0700
User-agent: Mozilla Thunderbird

On 2024-07-24 12:27, Alejandro Colomar wrote:
POSIX leaves the value of *endptr unspecified if the base is invalid;
it is not unmodified.

Fine, we can let xstrtol do the same.


That, combined with the fact that POSIX allows implementations of
strtol(3) to set EINVAL when no digits are found, makes it impossible to
portably check if the base was valid after the call.

I don't see why not. Current gnulib xstrtol.c does something reasonable if the base is invalid. Why isn't that good enough?


-  char *t_ptr = nullptr;
+  char *t_ptr;
    char **p = endptr ? endptr : &t_ptr;
+ *p = (char *) nptr;
+
+  if (base < 0 || base == 1 || 36 < base)
+    return LONGINT_INVALID;
+

This would cause xstrtol to fail even if the underlying strtol supports base 1, base 64, etc. Why would we want to do that?


I'm tired of strtol(3).  :)

Likewise. This issue about an invalid base is unimportant in practice, as the base is almost invariably a valid constant.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]