qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NUL


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NULL
Date: Fri, 23 Nov 2012 17:25:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

Il 23/11/2012 17:16, Andreas Färber ha scritto:
>> > @@ -430,7 +430,7 @@ Object *object_dynamic_cast_assert(Object *obj, const 
>> > char *typename)
>> >  
>> >      inst = object_dynamic_cast(obj, typename);
>> >  
>> > -    if (!inst) {
>> > +    if (!inst && obj) {
>> >          fprintf(stderr, "Object %p is not an instance of type %s\n",
>> >                  obj, typename);
>> >          abort();
> This is followed by return inst;
> 
> Since this function clearly has assert in the name I don't think this is
> right. I would expect %p to print 0x0 and the function to abort.

I think it's okay to segfault in this case.

Otherwise you need to replace this simple cast+check pair:

    SCSIDevice *s = SCSI_DEVICE(some->long.expressio[n]);
    if (!s) {
        return;
    }

with something that is more complex:

    DeviceState *d = some->long.expressio[n];
    SCSIDevice *s;

    if (!d) {
        return;
    }
    s = SCSI_DEVICE(d);

Paolo



reply via email to

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