public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/30371] New: C2x strtol binary constant handling is incomplete
@ 2023-04-18 17:44 bruno at clisp dot org
  2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bruno at clisp dot org @ 2023-04-18 17:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30371

            Bug ID: 30371
           Summary: C2x strtol binary constant handling is incomplete
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: bruno at clisp dot org
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 14838
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14838&action=edit
proposed fix

In the functions strtol/strtoul/strtoll/strtoull, support for binary
constants (such as 0b100111), as specified in ISO C 2x, was added
in glibc commit 64924422a99690d147a166b4de3103f3bf3eaf6c, on 2023-02-17.

But it is incomplete: The special input string "0b" with no binary digits
is not handled.

Here's a test case:
==================== tst-strtol-binary-no-digits.c ====================
#include <assert.h>
#include <errno.h>
#include <stdlib.h>

int main ()
{
  {
    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);
  }
}
=======================================================================

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.

I previously reported this to libc-alpha at
https://sourceware.org/pipermail/libc-alpha/2023-March/146367.html
but I now realize that this was not the proper reporting channel.
Sorry about that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-03 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 17:44 [Bug libc/30371] New: C2x strtol binary constant handling is incomplete bruno at clisp dot org
2023-04-18 19:42 ` [Bug libc/30371] " kdudka at redhat dot com
2023-04-18 21:08 ` eblake at redhat dot com
2023-04-18 21:13 ` eblake at redhat dot com
2023-04-18 21:42 ` bruno at clisp dot org
2023-04-19  2:46 ` sam at gentoo dot org
2023-04-20 14:58 ` mliska at suse dot cz
2023-05-22 16:42 ` eggert at cs dot ucla.edu
2023-07-03 20:14 ` bruno at clisp dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).