From: "Andreas Färber" <afaerber@suse.de>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
qemu-stable@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>,
Bruce Rogers <brogers@suse.com>, Lin Ma <lma@suse.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/7] string-input-visitor: Fix uint64 parsing
Date: Wed, 11 Nov 2015 20:26:26 +0100 [thread overview]
Message-ID: <56439662.3050406@suse.de> (raw)
In-Reply-To: <56055EED.2070503@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3729 bytes --]
Am 25.09.2015 um 16:49 schrieb Eric Blake:
> On 09/25/2015 06:39 AM, Andreas Färber wrote:
>> All integers would get parsed by strtoll(), not handling the case of
>> UINT64 properties with the most significient bit set.
>>
>> Implement a .type_uint64 visitor callback, reusing the existing
>> parse_str() code through a new argument, using strtoull().
>>
>> As a bug fix, ignore warnings about preference of qemu_strto[u]ll().
>>
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
>> qapi/string-input-visitor.c | 57 +++++++++++++++++++++++++++++++++++++++++----
>> 1 file changed, 52 insertions(+), 5 deletions(-)
>>
>
>> @@ -50,7 +50,11 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
>>
>> do {
>> errno = 0;
>> - start = strtoll(str, &endptr, 0);
>> + if (u64) {
>> + start = strtoull(str, &endptr, 0);
>
> accepts the range [-ULLONG_MAX, ULLONG_MAX] (with 2s complement
> wraparound). Do you really want -1 being a synonym for ULLONG_MAX, or do
> you want to explicitly reject leading '-' when parsing unsigned
> (arguments can be made for both behaviors; in fact, libvirt has two
> separate wrappers for parsing uint64_t depending on which behavior is
> wanted)
>
>> + } else {
>> + start = strtoll(str, &endptr, 0);
>
> accepts the range [LLONG_MIN, LLONG_MAX] (that is, roughly half the
> range of the unsigned version)
No one has further commented on this, so I take it no further changes
are required here for now.
>> + }
>> if (errno == 0 && endptr > str) {
>> if (*endptr == '\0') {
>> cur = g_malloc0(sizeof(*cur));
>> @@ -60,7 +64,7 @@ static void parse_str(StringInputVisitor *siv, Error **errp)
>> range_compare);
>> cur = NULL;
>> str = NULL;
>> - } else if (*endptr == '-') {
>> + } else if (*endptr == '-' && !u64) {
>
> Why do you not want to handle ranges when using unsigned numbers?
For some reason I must've read this as handling negative numbers, which
we wouldn't have for unsigned numbers...
However, since there is only one .start_list() callback, which passes
!u64 to retain previous behavior, we would never actually run into this
code path today. I've reverted my change and duplicated the strtoull()
handling instead nonetheless.
>>
>> +static void parse_type_uint64(Visitor *v, uint64_t *obj, const char *name,
>> + Error **errp)
>> +{
>> + StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
>> +
>> + if (!siv->string) {
>> + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
>> + "integer");
>> + return;
>> + }
> ...
>
> That's a lot of copy-and-paste. Can't you make parse_type_int64() and
> parse_type_uint64() both call into a single helper method, that contains
> the guts of the existing parse_type_int64() and adds a single parameter
> for the one place where the two functions differ on their call to
> parse_str()?
I don't see how. They have different signatures, and there's a lot of
gotos that differ in the error message. I'm all for sharing code but it
seems more work refactoring that code for reuse than duplication saved.
If you have a concrete suggestion how to improve it, please share a diff
or let's do that as follow-up.
Regards,
Andreas
--
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-11-11 19:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 12:39 [Qemu-devel] [PATCH 0/7] visitor: Fix uint64 parsing for scsi-disk wwn Andreas Färber
2015-09-25 12:39 ` [Qemu-devel] [PATCH 1/7] string-input-visitor: Fix uint64 parsing Andreas Färber
2015-09-25 14:49 ` Eric Blake
2015-11-11 19:26 ` Andreas Färber [this message]
2015-09-30 13:19 ` Markus Armbruster
2015-09-30 13:23 ` Andreas Färber
2015-09-30 13:48 ` Eric Blake
2015-09-30 13:47 ` Eric Blake
2015-09-25 12:39 ` [Qemu-devel] [PATCH 2/7] test-string-input-visitor: Add int test case Andreas Färber
2015-09-25 14:50 ` Eric Blake
2015-09-25 12:39 ` [Qemu-devel] [PATCH 3/7] test-string-input-visitor: Add uint64 test Andreas Färber
2015-09-25 14:55 ` Eric Blake
2015-09-25 12:39 ` [Qemu-devel] [PATCH 4/7] tests: Add QOM property unit tests Andreas Färber
2015-09-25 14:58 ` Eric Blake
2015-09-25 15:01 ` Daniel P. Berrange
2015-11-11 19:52 ` Andreas Färber
2015-09-25 12:39 ` [Qemu-devel] [PATCH 5/7] tests: Add scsi-disk test Andreas Färber
2015-09-25 12:39 ` [Qemu-devel] [PATCH 6/7] cutils: Normalize qemu_strto[u]ll() signature Andreas Färber
2015-09-25 12:42 ` Paolo Bonzini
2015-09-25 12:44 ` Andreas Färber
2015-09-25 12:56 ` Paolo Bonzini
2015-09-25 13:27 ` Andreas Färber
2015-09-25 13:47 ` Paolo Bonzini
2015-09-25 14:59 ` Eric Blake
2015-09-25 12:39 ` [Qemu-devel] [PATCH 7/7] string-input-visitor: Use qemu_strto[u]ll() Andreas Färber
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=56439662.3050406@suse.de \
--to=afaerber@suse.de \
--cc=armbru@redhat.com \
--cc=brogers@suse.com \
--cc=eblake@redhat.com \
--cc=lma@suse.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.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 NNTP newsgroup(s).