[libvirt] [PATCH] snapashot: Improve logic of virDomainMomentMoveChildren

Eric Blake eblake at redhat.com
Thu Mar 28 15:34:59 UTC 2019


On 3/28/19 10:18 AM, Ján Tomko wrote:
> s/snapashot/snapshot/
> 

I've been making that one a lot; will fix.

> On Thu, Mar 28, 2019 at 09:05:31AM -0500, Eric Blake wrote:
>> Even though Coverity can prove that 'last' is always set if the prior
>> loop executed, gcc 8.0.1 cannot:
>>

>> +++ b/src/conf/virdomainmomentobjlist.c
>> @@ -164,18 +164,17 @@ void
>> virDomainMomentMoveChildren(virDomainMomentObjPtr from,
>>                             virDomainMomentObjPtr to)
>> {
>> -    virDomainMomentObjPtr child;
>> -    virDomainMomentObjPtr last;
>> +    virDomainMomentObjPtr child = from->first_child;
>>
>> -    if (!from->first_child)
>> -        return;
> 
> From the code-change point-of view, by removing this condition,
> 
>> -    for (child = from->first_child; child; child = child->sibling) {
>> +    while (child) {
>>         child->parent = to;
>> -        if (!child->sibling)
>> -            last = child;
>> +        if (!child->sibling) {
>> +            child->sibling = to->first_child;
>> +            break;
>> +        }
>> +        child = child->sibling;
>>     }
>>     to->nchildren += from->nchildren;
>> -    last->sibling = to->first_child;
>>     to->first_child = from->first_child;
> 
> this possibly erases 'to->first_child' if 'from' does not have any.

Oh, good point. I'll keep the early exit for (!from->nchildren) then,

> But the callers are reasonable and only call this if (from->nchildren)

because I'm not certain that all future callers will be reasonable.

> 
>>     from->nchildren = 0;
>>     from->first_child = NULL;
> 
> Reviewed-by: Ján Tomko <jtomko at redhat.com>

I'll go ahead and push this one with those fixes.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190328/b4cd8513/attachment-0001.sig>


More information about the libvir-list mailing list