summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2019-03-28 09:00:59 -0500
committerEric Blake <eblake@redhat.com>2019-03-28 10:38:11 -0500
commit83b1808ca2605b631828038094e96dcf8cc5e442 (patch)
treea1271900973719e102ef3fccd71544563979ca0e
parent3f7cba3f5ea1731b9028b89b671cbd7e7d5e0421 (diff)
downloadlibvirt-83b1808ca2605b631828038094e96dcf8cc5e442.tar.gz
snapshot: Improve logic of virDomainMomentMoveChildren
Even though Coverity can prove that 'last' is always set if the prior loop executed, gcc 8.0.1 cannot: 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; ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ Rewrite the loop to a form that should be easier for static analysis to work with. Fixes: ced0898f86bf Reported-by: Bjoern Walk <bwalk@linux.ibm.com> Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
-rw-r--r--src/conf/virdomainmomentobjlist.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
index b9ca5b1318..65e82f632c 100644
--- a/src/conf/virdomainmomentobjlist.c
+++ b/src/conf/virdomainmomentobjlist.c
@@ -164,18 +164,19 @@ void
virDomainMomentMoveChildren(virDomainMomentObjPtr from,
virDomainMomentObjPtr to)
{
- virDomainMomentObjPtr child;
- virDomainMomentObjPtr last;
+ virDomainMomentObjPtr child = from->first_child;
- if (!from->first_child)
+ if (!from->nchildren)
return;
- 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;
from->nchildren = 0;
from->first_child = NULL;