This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/18246] New: scanf "%2d" can incorrectly parse "0x" same for "%2f" with "1e"


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

            Bug ID: 18246
           Summary: scanf "%2d" can incorrectly parse "0x" same for "%2f"
                    with "1e"
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: nszabolcs at gmail dot com
                CC: drepper.fsp at gmail dot com

BZ #1765 was closed with won't fix, 0x is another similar corner case.

0x prefix should not be parsed as a valid decimal number.

following code prints:
got 1 fields (x=0), expected 0
got 1 fields (y=1), expected 0


#include <stdio.h>
int main()
{
int x;
float y;
int r;

r = sscanf("0x12", "%2d", &x);
if (r != 0)
        printf("got %d fields (x=%d), expected 0\n", r, x);

r = sscanf("1e12", "%2f", &y);
if (r != 0)
        printf("got %d fields (y=%g), expected 0\n", r, y);
}

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]