[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v1 3/6] qapi: assert that visitor impls have req

From: Eric Blake
Subject: Re: [Qemu-block] [PATCH v1 3/6] qapi: assert that visitor impls have required callbacks
Date: Tue, 7 Jun 2016 09:40:25 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

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:
>   Segmentation fault (core dumped)
> 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:
>   qapi/qapi-visit-core.c:32: visit_start_struct: Assertion `v->start_struct 
> != ((void *)0)' failed.
> Signed-off-by: Daniel P. Berrange <address@hidden>
> ---
>  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).

> 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 != VISITOR_OUTPUT || *obj);
>      }
> +    assert(v->start_struct != NULL);

I'd have written it assert(v->start_struct) (explicit comparison against
NULL matters in Java, but is just line noise in C).

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]