From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wx13g-0005Qd-QS for qemu-devel@nongnu.org; Tue, 17 Jun 2014 17:36:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wx13c-00041b-HB for qemu-devel@nongnu.org; Tue, 17 Jun 2014 17:36:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32183) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wx13c-00041X-7h for qemu-devel@nongnu.org; Tue, 17 Jun 2014 17:36:44 -0400 Message-ID: <53A0B4E3.1020608@redhat.com> Date: Tue, 17 Jun 2014 15:36:35 -0600 From: Eric Blake MIME-Version: 1.0 References: <1403021756-15960-1-git-send-email-mst@redhat.com> <1403021756-15960-92-git-send-email-mst@redhat.com> In-Reply-To: <1403021756-15960-92-git-send-email-mst@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KP0FRI5D11HoMmjn8f2ah8BsrKITHd4e0" Subject: Re: [Qemu-devel] [PULL 091/103] qapi: make string input visitor parse int list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Hu Tao , Markus Armbruster , Luiz Capitulino , Anthony Liguori This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KP0FRI5D11HoMmjn8f2ah8BsrKITHd4e0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/17/2014 11:41 AM, Michael S. Tsirkin wrote: > From: Hu Tao >=20 > Signed-off-by: Hu Tao > Acked-by: Michael S. Tsirkin > Tested-by: Michael S. Tsirkin > Signed-off-by: Michael S. Tsirkin >=20 > MST: split up patch > --- > qapi/string-input-visitor.c | 195 ++++++++++++++++++++++++++++++= ++++++-- > tests/test-string-input-visitor.c | 36 +++++++ > 2 files changed, 223 insertions(+), 8 deletions(-) >=20 > +static void parse_str(StringInputVisitor *siv, Error **errp) > +{ > + char *str =3D (char *) siv->string; > + long long start, end; > + Range *cur; > + char *endptr; > + > + if (siv->ranges) { > + return; > + } > + > + errno =3D 0; > + do { > + start =3D strtoll(str, &endptr, 0); > + if (errno =3D=3D 0 && endptr > str && INT64_MIN <=3D start && > + start <=3D INT64_MAX) { INT64_MIN <=3D start && start <=3D INT64_MAX is dead code (always true, unless you are on some weird platform where long long is larger than int64_t). > + if (*endptr =3D=3D '\0') { > + cur =3D g_malloc0(sizeof(*cur)); > + cur->begin =3D start; > + cur->end =3D start + 1; > + siv->ranges =3D g_list_insert_sorted_merged(siv->range= s, cur, > + range_compar= e); > + cur =3D NULL; > + str =3D NULL; > + } else if (*endptr =3D=3D '-') { > + str =3D endptr + 1; > + end =3D strtoll(str, &endptr, 0); > + if (errno =3D=3D 0 && endptr > str && > + INT64_MIN <=3D end && end <=3D INT64_MAX && start = <=3D end && Another dead line. =2E.. > + } else { > + goto error; > + } > + } while (str); Your code has a bug. You fail to reset errno =3D 0 prior to resuming the= next iteration of the while loop, even though you have called intermediate functions that may have clobbered errno. You'll need to submit a followup patch to fix it. > +static void test_visitor_in_intList(TestInputVisitorData *data, > + const void *unused) > +{ > + int64_t value[] =3D {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20}; > + int16List *res =3D NULL, *tmp; > + Error *errp =3D NULL; > + Visitor *v; > + int i =3D 0; > + > + v =3D visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); Should you also test the ability to create ranges of negative numbers, such as "-3--1", since integers are signed? > + > + visit_type_int16List(v, &res, NULL, &errp); > + g_assert(errp =3D=3D NULL); It's shorter to write this as one line: visit_type_int16List(v, &res, NULL, &error_abort); --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --KP0FRI5D11HoMmjn8f2ah8BsrKITHd4e0 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJToLTjAAoJEKeha0olJ0NqhnkH/R7pejGSUXpxlF6emrhmmwTT YofNzfuOfORwmBSKe47G7/6ysOXskKJ6+/LjtmHLRRC4zbxI9HuZzjH1iaKvqktI oOmbqgNGD3+Pf8yoFUJnSltZjZcYYoTUDZ7VSz05+Ay6STg/NmLUIpFN8LcBsFN4 WA3CTbzxBgLHqxb+S75m0tVM0kYMAS6K/h6MLZDUZIvg7zhp0pFRgUPFiACjonLZ wu4P7i+1u8EtFia6mgI0dhITnwbEUVMP5IZHWS8Fo3hrar9HW6C/yEhjDEYH4yLk /YW9HwLeThubxYCl8h+ifEFGqNkWSD0WGJ9rJ9nqwL9XAjYxgoDEscoI7T+5MyM= =LUZ5 -----END PGP SIGNATURE----- --KP0FRI5D11HoMmjn8f2ah8BsrKITHd4e0--