From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvWVm-0002aV-Hf for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:10:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvWVk-0002zw-SW for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:10:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvWVk-0002zr-Bg for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:10:48 -0500 Message-ID: <50F6DF12.8030703@redhat.com> Date: Wed, 16 Jan 2013 10:10:42 -0700 From: Eric Blake MIME-Version: 1.0 References: <1358349851-20960-1-git-send-email-ehabkost@redhat.com> <1358349851-20960-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1358349851-20960-2-git-send-email-ehabkost@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2TENCWJSCMSLHIHLVMPKM" Subject: Re: [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: Laszlo Ersek , Chegu Vinod , qemu-devel@nongnu.org, Anthony Liguori This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2TENCWJSCMSLHIHLVMPKM Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/16/2013 08:24 AM, 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 > Parsing functions for signed ints and floats will be submitted later. >=20 > parse_uint_full() has all the checks made by opts_type_uint64() at > opts-visitor.c: >=20 > - Check for NULL (returns -EINVAL) > - Check for negative numbers (returns -ERANGE) > - Check for empty string (returns -EINVAL) > - Check for overflow or other errno values set by strtoll() (returns > -errno) > - Check for end of string (reject invalid characters after number) > (returns -EINVAL) >=20 > parse_uint() does everything above except checking for the end of the > string, so callers can continue parsing the remainder of string after > the number. >=20 > Unit tests included. >=20 > [1] string-input-visitor.c:parse_int() could use the same parsing code > used by opts-visitor.c:opts_type_int(), instead of duplicating that= > logic. >=20 > Signed-off-by: Eduardo Habkost > --- > Cc: Laszlo Ersek > Cc: Eric Blake > --- > +++ b/tests/test-cutils.c > + * > + * Permission is hereby granted, free of charge, to any person obtaini= ng a copy Interesting that you chose a BSD license instead of GPL, but doesn't affect my review. Your test case lacks test of octal or hexadecimal input strings; is that worth adding? > +++ b/util/cutils.c > @@ -270,6 +270,82 @@ int64_t strtosz(const char *nptr, char **end) > return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); > } > =20 > +/* Try to parse an unsigned integer > + * > + * Error checks done by the function: > + * - NULL pointer will return -EINVAL. > + * - Empty strings will return -EINVAL. > + * - Overflow errors or other errno values set by strtoull() will > + * return -errno (-ERANGE in case of overflow). > + * - Differently from strtoull(), values starting with a minus sign ar= e > + * rejected (returning -ERANGE). Interesting that you chose to reject negative numbers, even though strtoull() is required to accept them. But you documented it and tested for it, so I can live with it. > + errno =3D 0; > + val =3D strtoull(s, &endp, 0); > + if (errno) { > + r =3D -errno; Why two spaces? Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2TENCWJSCMSLHIHLVMPKM 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/ iQEcBAEBCAAGBQJQ9t8SAAoJEKeha0olJ0NqaroIAIFLAKdCwWShJFFUUZ53HHD8 W77EGotNQ/D2LW5mTKNvnKl0tcBqotMdte+z7aSUNSuBbDGkJUXI3o1oN35jFZey yBdF0IBOtyM986retxU0YesxbsVOUWjA6KhV4KXgiQ3F0/JUWhB3Rn1niikq1wZO w7qhI6jIzdluaCZyfbbz36I1Gt3lJYgussfLFrMJ4H99qGAcdTLJAMykA4+K5MUk 9oGz6E0nf7cyn3+VUF9Wnmz1awKEGhGTUPvoATgOhzWvOFpcyRGESKogs3fF+X8Q Ne66RqzZEfM5whns5uiMlxlBYA/h00jU5BfNyWrFX7FDwa5c6degTA+p3lqtBYs= =liVD -----END PGP SIGNATURE----- ------enig2TENCWJSCMSLHIHLVMPKM--