From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfUJU-0005eK-6n for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:49:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfUJQ-0006ej-V1 for qemu-devel@nongnu.org; Fri, 25 Sep 2015 10:49:28 -0400 References: <1443184788-18859-1-git-send-email-afaerber@suse.de> <1443184788-18859-2-git-send-email-afaerber@suse.de> From: Eric Blake Message-ID: <56055EED.2070503@redhat.com> Date: Fri, 25 Sep 2015 08:49:17 -0600 MIME-Version: 1.0 In-Reply-To: <1443184788-18859-2-git-send-email-afaerber@suse.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ut7KOa4t7esdp3S92kVXsbN1erTHekRHq" Subject: Re: [Qemu-devel] [PATCH 1/7] string-input-visitor: Fix uint64 parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Andreas_F=c3=a4rber?= , qemu-devel@nongnu.org Cc: Markus Armbruster , qemu-stable@nongnu.org, Michael Roth , Bruce Rogers , Lin Ma , Paolo Bonzini This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ut7KOa4t7esdp3S92kVXsbN1erTHekRHq Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/25/2015 06:39 AM, Andreas F=C3=A4rber wrote: > All integers would get parsed by strtoll(), not handling the case of > UINT64 properties with the most significient bit set. >=20 > Implement a .type_uint64 visitor callback, reusing the existing > parse_str() code through a new argument, using strtoull(). >=20 > As a bug fix, ignore warnings about preference of qemu_strto[u]ll(). >=20 > Cc: qemu-stable@nongnu.org > Signed-off-by: Andreas F=C3=A4rber > --- > qapi/string-input-visitor.c | 57 +++++++++++++++++++++++++++++++++++++= ++++---- > 1 file changed, 52 insertions(+), 5 deletions(-) >=20 > @@ -50,7 +50,11 @@ static void parse_str(StringInputVisitor *siv, Error= **errp) > =20 > do { > errno =3D 0; > - start =3D strtoll(str, &endptr, 0); > + if (u64) { > + start =3D 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 =3D strtoll(str, &endptr, 0); accepts the range [LLONG_MIN, LLONG_MAX] (that is, roughly half the range of the unsigned version) > + } > if (errno =3D=3D 0 && endptr > str) { > if (*endptr =3D=3D '\0') { > cur =3D g_malloc0(sizeof(*cur)); > @@ -60,7 +64,7 @@ static void parse_str(StringInputVisitor *siv, Error = **errp) > range_compar= e); > cur =3D NULL; > str =3D NULL; > - } else if (*endptr =3D=3D '-') { > + } else if (*endptr =3D=3D '-' && !u64) { Why do you not want to handle ranges when using unsigned numbers? > =20 > +static void parse_type_uint64(Visitor *v, uint64_t *obj, const char *n= ame, > + Error **errp) > +{ > + StringInputVisitor *siv =3D DO_UPCAST(StringInputVisitor, visitor,= v); > + > + if (!siv->string) { > + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "n= ull", > + "integer"); > + return; > + } =2E.. 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()? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ut7KOa4t7esdp3S92kVXsbN1erTHekRHq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWBV7tAAoJEKeha0olJ0NqoG8H/1n50Srbr0hpZN+wShgCKW06 idqB0PqZWjOETSSOlEa2p2Dsor3UvbdQIb32NrIDuvUv0+0NR5tOEYwVRfOnPYGQ oHln0xJY3TCWixHAnin9y3mEvi/DSBAuxfomhZtk1jzq2iyFs/0LEwJOrDILYKSv Gwi7n/gVc82d93rTmfCHV9uQ6FEEPzxD4sP7aqbvJ+Ef71n/KE3jyotAW8sp/lVq bqzRJFXGoiGfkMh7wCWwUdCfzUw44puGkIuBLqt9cMG1VCLfWL9Zp4FtLyt4Z2fk 7rmfX7FtcHrSaFE1lZNxP8scFddbEvLgQV+ilrmELak2SDgAoaqiMfUDqdCdIJo= =mepN -----END PGP SIGNATURE----- --ut7KOa4t7esdp3S92kVXsbN1erTHekRHq--