From: Eric Blake <eblake@redhat.com>
To: Gnulib bugs <bug-gnulib@gnu.org>
Subject: mingw strtol bug
Date: Wed, 17 Mar 2021 08:08:29 -0500 [thread overview]
Message-ID: <8cdc7539-3d8d-ada3-8fbb-a585fc6d8215@redhat.com> (raw)
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
next reply other threads:[~2021-03-17 13:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 13:08 Eric Blake [this message]
2021-04-02 19:00 ` mingw strtol bug Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8cdc7539-3d8d-ada3-8fbb-a585fc6d8215@redhat.com \
--to=eblake@redhat.com \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).