From nobody Tue Apr 30 07:44:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553781968857930.5260161953773; Thu, 28 Mar 2019 07:06:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6971530992C6; Thu, 28 Mar 2019 14:05:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2600518009; Thu, 28 Mar 2019 14:05:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 780FE180338B; Thu, 28 Mar 2019 14:05:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2SE5b97016058 for ; Thu, 28 Mar 2019 10:05:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7389E176A9; Thu, 28 Mar 2019 14:05:37 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12BBA5D6B3; Thu, 28 Mar 2019 14:05:34 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 28 Mar 2019 09:05:31 -0500 Message-Id: <20190328140531.24498-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: bwalk@linux.ibm.com Subject: [libvirt] [PATCH] snapashot: Improve logic of virDomainMomentMoveChildren X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 28 Mar 2019 14:06:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 'virDomainMomentMoveCh= ildren': ../../src/conf/virdomainmomentobjlist.c:178:19: error: 'last' may be used u= ninitialized in this function [-Werror=3Dmaybe-uninitialized] last->sibling =3D 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 Signed-off-by: Eric Blake Reviewed-by: J=C3=A1n Tomko --- Qualifies as a build-breaker fix, but I'd like a review before pushing. src/conf/virdomainmomentobjlist.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index b9ca5b1318..5a217056d1 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -164,18 +164,17 @@ void virDomainMomentMoveChildren(virDomainMomentObjPtr from, virDomainMomentObjPtr to) { - virDomainMomentObjPtr child; - virDomainMomentObjPtr last; + virDomainMomentObjPtr child =3D from->first_child; - if (!from->first_child) - return; - for (child =3D from->first_child; child; child =3D child->sibling) { + while (child) { child->parent =3D to; - if (!child->sibling) - last =3D child; + if (!child->sibling) { + child->sibling =3D to->first_child; + break; + } + child =3D child->sibling; } to->nchildren +=3D from->nchildren; - last->sibling =3D to->first_child; to->first_child =3D from->first_child; from->nchildren =3D 0; from->first_child =3D NULL; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list