bug-gnulib
[Top][All Lists]
Advanced

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

mingw strtol bug


From: Eric Blake
Subject: mingw strtol bug
Date: Wed, 17 Mar 2021 08:08:29 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0

I ran into a mingw bug on strtol() today, and don't see it documented or
worked around in gnulib:

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(void)
{
    unsigned long u;
    const char *str = "0x";
    char *end;
    errno = 0;
    u = strtoul(str, &end, 10);
    printf("%lu %s %d\n", u, end, errno);
    errno = 0;
    u = strtoul(str, &end, 16);
    printf("%lu %s %d\n", u, end, errno);
    errno = 0;
    u = strtoul(str, &end, 0);
    printf("%lu %s %d\n", u, end, errno);

    str = "0xq";
    errno = 0;
    u = strtoul(str, &end, 10);
    printf("%lu %s %d\n", u, end, errno);
    errno = 0;
    u = strtoul(str, &end, 16);
    printf("%lu %s %d\n", u, end, errno);
    errno = 0;
    u = strtoul(str, &end, 0);
    printf("%lu %s %d\n", u, end, errno);
    return 0;
}
$ gcc                    -o foo-linux -Wall foo.c
$ x86_64-w64-mingw32-gcc -o foo-mingw -Wall foo.c
$ ./foo-linux
0 x 0
0 x 0
0 x 0
0 xq 0
0 xq 0
0 xq 0
$ wine ./foo-mingw.exe 2>/dev/null
0 x 0
0 0x 0
0 0x 0
0 xq 0
0 0xq 0
0 0xq 0

In short, mingw (at least when run under wine, I did not actually test
on a Windows machine) fails to properly consume '0' when parsing in base
16 or 0 when there are no hex digits after a trailing garbage of 'x' or 'X'.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

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