On 3/28/19 2:40 AM, Bjoern Walk wrote:
>>>> +/* Take all children of @from and convert them into
children of @to. */
>>>> +void
>>>> +virDomainSnapshotMoveChildren(virDomainSnapshotObjPtr from,
>>>> + virDomainSnapshotObjPtr to)
>>>> +{
>>>> + virDomainSnapshotObjPtr child;
>>>> + virDomainSnapshotObjPtr last;
>>>> +
>>>> + for (child = from->first_child; child; child = child->sibling)
{
>>>> + child->parent = to;
>>>> + if (!child->sibling)
>>>> + last = child;
>>>> + }
>>>> + to->nchildren += from->nchildren;
>>>> + last->sibling = to->first_child;
>>>
>>> Silly Coverity compiler gets quite confused thinking that @last couldn't
>>> be set while not considering the above loop couldn't end without it
>>> unless of course from->first_child == NULL I suppose, which would be a
>>> different issue. Still if before the for loop we check "if
>>> (!from->first_child) return;", then coverity is happy.
>>
>> Good find from Coverity. If there are no children to move, I do need the
>> early exit, so I'll squash that in.
>
> Did you forget this? Function is pushed in this (broken?) version and I
> get a warning/error on GCC 8.0.1.
Sorry, no morning coffee yet, the fix is in, but I still get a GCC
warning:
CC conf/libvirt_conf_la-virdomainmomentobjlist.lo
../../src/conf/virdomainmomentobjlist.c: In function
'virDomainMomentMoveChildren':
../../src/conf/virdomainmomentobjlist.c:178:19: error: 'last' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
last->sibling = to->first_child;
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [Makefile:9650: conf/libvirt_conf_la-virdomainmomentobjlist.lo] Error 1
So gcc isn't as smart as Coverity at seeing that it will always be
initialized.
This fixes it:
diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
index 92cf52dd..2e9343ff 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -165,7 +165,7 @@ virDomainMomentMoveChildren(virDomainMomentObjPtr from,
virDomainMomentObjPtr to)
{
virDomainMomentObjPtr child;
- virDomainMomentObjPtr last;
+ virDomainMomentObjPtr last = NULL;
Yep, will push shortly as a build-fixer. I'm assuming you're okay if I
push it in your name, as you reported and posted the fix, even though it
wasn't the usual git format.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org