From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TwIRD-0007vS-R9 for qemu-devel@nongnu.org; Fri, 18 Jan 2013 15:21:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TwIRC-0006S6-Dj for qemu-devel@nongnu.org; Fri, 18 Jan 2013 15:21:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25440) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TwIRC-0006Rs-5N for qemu-devel@nongnu.org; Fri, 18 Jan 2013 15:21:18 -0500 Message-ID: <50F9AE7A.9010703@redhat.com> Date: Fri, 18 Jan 2013 13:20:10 -0700 From: Eric Blake MIME-Version: 1.0 References: <1358531842-16752-1-git-send-email-ehabkost@redhat.com> <50F9903F.8040609@redhat.com> <20130118194123.GO20133@otherpad.lan.raisama.net> In-Reply-To: <20130118194123.GO20133@otherpad.lan.raisama.net> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2DHDPICPKSPGEWSIOSRBH" Subject: Re: [Qemu-devel] [PATCH 1/8 v6] cutils: unsigned int parsing functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: Laszlo Ersek , qemu-devel@nongnu.org, Markus Armbruster , Anthony Liguori , Chegu Vinod , =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2DHDPICPKSPGEWSIOSRBH Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/18/2013 12:41 PM, Eduardo Habkost wrote: > There are lots of duplicate parsing code using strto*() in QEMU, and > most of that code is broken in one way or another. Even the visitors > code have duplicate integer parsing code[1]. This introduces functions > to help parsing unsigned int values: parse_uint() and parse_uint_full()= =2E >=20 > Changes v6: > - Return -ERANGE (and set *endptr beyond all digits) for negative > numbers > Suggested-by: Markus Armbruster > - Clarify that function will consume all digits even in case of > overflow/underflow > - Doesn't define *v as undefined in case parse_uint_full() finds extra= > characters. Explicitly document it as set to 0. Looks sane to me, except for the introduction of one typo (please, can whoever queues up the PULL request just fix that, without needing to see a v7)? >=20 > 6 version of a simple integer parsing function. This is getting funny. > :-) Yeah, but just think how much easier parse_int() is going to be :) > --- > include/qemu-common.h | 4 + > tests/Makefile | 3 + > tests/test-cutils.c | 251 ++++++++++++++++++++++++++++++++++++++++++= ++++++++ > util/cutils.c | 99 ++++++++++++++++++++ > 4 files changed, 357 insertions(+) > create mode 100644 tests/test-cutils.c Reviewed-by: Eric Blake > + * > + * Parsed syntax is like strtoull()'s: arbitrary whitespace, a single = optional > + * '+' or '-', an optional "0x"if @base is 0 or 16, one or more digits= =2E s/"0x"if/"0x" if/ > + > +/** > + * parse_uint_full: > + * > + * @s: String to parse > + * @value: Destination for parsed integer value > + * @base: integer base, between 2 and 36 inclusive, or 0 > + * > + * Parse unsigned integer from entire string > + * > + * Have the same behavior of parse_uint(), but with an additional chec= k > + * for additional data after the parsed number. If extra characters ar= e present > + * after the parsed number, the function will return -EINVAL, and *@v = will > + * be set to 0. > + */ > +int parse_uint_full(const char *s, unsigned long long *value, int base= ) [Side note - in libvirt, we have just one function instead of two; you get the parse_uint_full semantics by passing NULL for endptr to the parse_uint counterpart. But I'm fine with your approach of mandating endptr to be a non-NULL pointer to parse_uint, and having a second function for the case where no end characters are allowed.] --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2DHDPICPKSPGEWSIOSRBH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJQ+a56AAoJEKeha0olJ0NqMP0H/3BYrjVpVDJOjpAUomXt3mZ4 HOpaFI1oDI/ymuKRkPIhAv3BPjS4n+dRzqK3wIQLNu+eqd08ieOKN1hVcCxxQyde qOtci502HGIXVLgPkDFUAwoK9X6AhW/7bC29kFZxkqGRXLIYWOgrzQ0t2ZkosTRx 9E1xGtbmz5OyyCxekQqIocweZXgX9w18iGUTBoi9lFlSh5CTGDUooMKG8a+CdGep /uPEU7FgTnkGQ3r5PuNHRg5UXwxYM7xaWE3DkKY4/kb2aOlEl5k1Hpdur7PRWaAm Ja0a8r+xRTZUxBzAVaJBh08Hgckhus/lOw+Nue6yPIIo4AKSzgklglyf2tJWyqY= =ydhn -----END PGP SIGNATURE----- ------enig2DHDPICPKSPGEWSIOSRBH--