提交 83b1808c 编写于 作者: E Eric Blake

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: ced0898fReported-by: NBjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 3f7cba3f
...@@ -164,18 +164,19 @@ void ...@@ -164,18 +164,19 @@ void
virDomainMomentMoveChildren(virDomainMomentObjPtr from, virDomainMomentMoveChildren(virDomainMomentObjPtr from,
virDomainMomentObjPtr to) virDomainMomentObjPtr to)
{ {
virDomainMomentObjPtr child; virDomainMomentObjPtr child = from->first_child;
virDomainMomentObjPtr last;
if (!from->first_child) if (!from->nchildren)
return; return;
for (child = from->first_child; child; child = child->sibling) { while (child) {
child->parent = to; child->parent = to;
if (!child->sibling) if (!child->sibling) {
last = child; child->sibling = to->first_child;
break;
}
child = child->sibling;
} }
to->nchildren += from->nchildren; to->nchildren += from->nchildren;
last->sibling = to->first_child;
to->first_child = from->first_child; to->first_child = from->first_child;
from->nchildren = 0; from->nchildren = 0;
from->first_child = NULL; from->first_child = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册