From: Eric Blake <eblake@redhat.com>
To: Thomas Huth <thuth@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org
Cc: philmd@redhat.com
Subject: Re: [PATCH v2 1/1] utils: Use fixed-point arithmetic in qemu_strtosz
Date: Wed, 17 Mar 2021 08:02:06 -0500 [thread overview]
Message-ID: <6aa20801-f310-9755-1b29-e40c303428a3@redhat.com> (raw)
In-Reply-To: <762b8658-f16f-5d64-2a6e-0a69b2fbeccf@redhat.com>
On 3/17/21 6:16 AM, Eric Blake wrote:
> On 3/17/21 2:09 AM, Thomas Huth wrote:
>> On 15/03/2021 16.58, Richard Henderson wrote:
>>> Once we've parsed the fractional value, extract it into an integral
>>> 64-bit fraction. Perform the scaling with integer arithemetic, and
>>> simplify the overflow detection.
>>
>> I've put this patch in my local branch, but I'm still getting a failure
>> in the cutils test, this time in the Cirrus-CI with the MinGW build:
>>
>> https://cirrus-ci.com/task/5413753530351616?command=test#L543
>>
>> Is it related or is this a different bug?
>
> ERROR test-cutils - Bail out!
> ERROR:../tests/unit/test-cutils.c:2233:test_qemu_strtosz_trailing:
> assertion failed (res == 0): (1024 == 0)
>
> That's testing behavior on:
>
> str = "0x";
> err = qemu_strtosz(str, &endptr, &res);
>
> which should parse as "0" with a suffix of 'x'. It is an independent
> issue (unrelated to the rounding issues fixed in rth's patch), and
> rather appears to be a bug in mingw's libc for strtoull although I have
> not actually set up an environment to test that assumption yet.
Confirmed:
$ 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);
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);
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 xq 0
0 xq 0
$ wine ./foo-mingw 2>/dev/null
0 x 0
0 0x 0
0 xq 0
0 0xq 0
Mingw has a bug (and therefore so do all our qemu_strto* functions) when
parsing "0xgarbage" with a base of 0 or 16, in that it fails to advance
past the leading '0' (which is a valid parse). Patch coming up.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
prev parent reply other threads:[~2021-03-17 13:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 15:58 [PATCH v2 0/1] Fix qemu_strtosz regression Richard Henderson
2021-03-15 15:58 ` [PATCH v2 1/1] utils: Use fixed-point arithmetic in qemu_strtosz Richard Henderson
2021-03-15 16:17 ` Philippe Mathieu-Daudé
2021-03-15 16:30 ` Eric Blake
2021-03-17 7:09 ` Thomas Huth
2021-03-17 11:16 ` Eric Blake
2021-03-17 13:02 ` Eric Blake [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6aa20801-f310-9755-1b29-e40c303428a3@redhat.com \
--to=eblake@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/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 NNTP newsgroup(s).