From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAJ7J-0002NC-UK for qemu-devel@nongnu.org; Tue, 07 Jun 2016 11:40:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAJ7I-0002xU-QQ for qemu-devel@nongnu.org; Tue, 07 Jun 2016 11:40:33 -0400 References: <1465294275-8733-1-git-send-email-berrange@redhat.com> <1465294275-8733-4-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <5756EAE9.2040108@redhat.com> Date: Tue, 7 Jun 2016 09:40:25 -0600 MIME-Version: 1.0 In-Reply-To: <1465294275-8733-4-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KGP0Meitv7cwSHN7jNvtNL35j6LF4OlgL" Subject: Re: [Qemu-devel] [PATCH v1 3/6] qapi: assert that visitor impls have required callbacks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Max Reitz , Markus Armbruster , Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KGP0Meitv7cwSHN7jNvtNL35j6LF4OlgL Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/07/2016 04:11 AM, Daniel P. Berrange wrote: > Not all visitor implementations supply the full set of > visitor callback functions. For example, the string > output visitor does not provide 'start_struct' and > friends. If you don't know this and feed it an object > that uses structs, you'll get a crash: >=20 > Segmentation fault (core dumped) >=20 > Crashing is fine, because this is a programmer mistake, > but we can improve the error message upon crash to make > it obvious what failed by adding assert()s: >=20 > qapi/qapi-visit-core.c:32: visit_start_struct: Assertion `v->start_st= ruct !=3D ((void *)0)' failed. >=20 > Signed-off-by: Daniel P. Berrange > --- > qapi/qapi-visit-core.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) Up to Markus if he likes this (I think I've proposed the idea, but never actually written it as a patch, because he implied that the core dump still points people in the right direction). >=20 > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c > index eada467..3b5efbe 100644 > --- a/qapi/qapi-visit-core.c > +++ b/qapi/qapi-visit-core.c > @@ -29,6 +29,7 @@ void visit_start_struct(Visitor *v, const char *name,= void **obj, > assert(size); > assert(v->type !=3D VISITOR_OUTPUT || *obj); > } > + assert(v->start_struct !=3D NULL); I'd have written it assert(v->start_struct) (explicit comparison against NULL matters in Java, but is just line noise in C). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --KGP0Meitv7cwSHN7jNvtNL35j6LF4OlgL 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/ iQEcBAEBCAAGBQJXVurpAAoJEKeha0olJ0Nq/K0H/3aR4TVzKFJyRelduFpR0e8M uEkEGZ7fLmvcoXOndn1XRf5njo5NjfjCct8oFiIejqOEJCy9ncrAjQEL+x5IuHLN y8h/jt4Afd/3YuvEkvcHxCg+XsPL3ivIRAQxVIC5txxxDCxPBJttx7iW8AE58mxn TCCoc7QI/eHzb0up5LYJcy59Qp8R+kHI1Q1cPJZ4mdkZj8OT298RdhC4vL6jalCA B8yqJbWKjPni9FW4aX01EoK3ndHzyCRRm5Asla6Viu6bJNPlGTfDrQaHQ0FIfLSq qLiL6fleLCBN2+4LvtUVDxiZzttdYuK+PYmRkcOLF7HgfRiyFoAP63NRg2PmnI8= =oxDw -----END PGP SIGNATURE----- --KGP0Meitv7cwSHN7jNvtNL35j6LF4OlgL--