[libvirt] [PATCHv2 06/17] qemu: implement <model> subelement to <controller>

John Ferlan jferlan at redhat.com
Wed Jul 22 20:32:15 UTC 2015



On 07/22/2015 04:18 PM, Laine Stump wrote:
> On 07/22/2015 03:54 PM, John Ferlan wrote:
...

>>> +                if (deviceName &&
>>> +                    VIR_STRDUP(options->type, deviceName) < 0)
>>> +                    goto cleanup;
>>> +
>> As has been told to me before - virStrdup/VIR_STRDUP is "tolerant" of
>> deviceName == NULL returning 0 if it's NULL, so just:
>>
>>     if (VIR_STRDUP(options->type, deviceName) < 0)
>>         goto cleanup;
>>
>> is necessary
> 
> But that would set options->type to NULL in the case that deviceName
> hadn't been set, and we don't want that. Consider for a moment that
> options->type had already been explicitly set to "pci-bridge". Since
> options->type != NULL, deviceName would remain NULL, we would get to the
> VIR_STRDUP() and unconditionally set options->type to NULL, losing the
> value that we actually wanted (and leaking it to boot).
> 
> Hmm. I guess my logic *is* a bit backwards though :-) Instead I should
> say "if (!options->type && VIR_STRDUP(blah)...)"
> 

Oh right.  I'm fine with (!options->type checking since that's what
you're trying to not overwrite

John




More information about the libvir-list mailing list