C2x strtol binary constant handling: Fix special case "0b"
Bruno Haible
bruno@clisp.org
Thu Mar 16 15:14:58 GMT 2023
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-C2x-strtol-binary-constant-handling-Fix-special-case.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20230316/f4ab606d/attachment-0001.bin>
More information about the Libc-alpha
mailing list