C2x strtol binary constant handling: Fix special case "0b"

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Mar 16 21:01:54 GMT 2023



On 16/03/23 12:14, Bruno Haible wrote:
> Hi Joseph,
> 
> While adding C2x support to the strtol, strtoll, strtoul, strtoull
> functions in Gnulib, I was glad to see that you have already done
> the support in glibc. But I noticed that the glibc implementation
> apparently does not handle the input "0b" correctly. The unit test
> cases for this special case are:
> 
>   {
>     const char input[] = "0b";
>     char *ptr;
>     long result;
>     errno = 0;
>     result = strtol (input, &ptr, 2);
>     assert (result == 0L);
>     assert (ptr == input + 1);
>     assert (errno == 0);
>   }
>   {
>     const char input[] = "0b";
>     char *ptr;
>     long result;
>     errno = 0;
>     result = strtol (input, &ptr, 0);
>     assert (result == 0L);
>     assert (ptr == input + 1);
>     assert (errno == 0);
>   }
> 
> and likewise for strtoll, strtoul, strtoull.
> 
> Find attached a correction for this. I have tested it in Gnulib (which
> has very similar source code as glibc for this functionality), not in
> Glibc directly. Therefore, please review thoroughly.
> 
> Bruno

Could you also add these testscase on strtol tests ?


More information about the Libc-alpha mailing list