From nobody Sun Feb 8 22:07:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664872418; cv=none; d=zohomail.com; s=zohoarc; b=QrWzE5QzRWk5GqMaV4McwBL36G8axMqyHasFxzSvBV2Uc1ql6CygK0FAVK98RvWVeaUNkSt5opxhzhi1XAt94ePiK3DvlkNL+ydI6x5NIaT9iCKYKu0p0nWGSjLZTAQZKRtEqOPdObfWPHxTaVl+pQph5VMJRWDXdA0ye74zlg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664872418; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6I7MgN63iSxr6uioLS+tRzCCmN7gydNvOTS8crouyJU=; b=HqFA+Ybu7nPhQghSSxfLKCx6487xyauagOLiJJKYBIpBGcZfN0EDqPrvlkRA8Q8PaPgCnw46M+64yGFtOuiBisYBBzwr4IyImGyg3gHvS39ivvFahpzdrkP+0A3qq1zeoe9Sk1ecmlKlF7ISq4lRc+NXKtFdv+6nDchC37JTP8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 166487241855868.03441923393416; Tue, 4 Oct 2022 01:33:38 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-464-D_0c6NEuMASZDd0_rQzxiA-1; Tue, 04 Oct 2022 04:33:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 661D52999B25; Tue, 4 Oct 2022 08:33:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 540801121315; Tue, 4 Oct 2022 08:33:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1189D1946A7F; Tue, 4 Oct 2022 08:33:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 628FB19465A2 for ; Tue, 4 Oct 2022 08:33:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 590A840C6EC3; Tue, 4 Oct 2022 08:33:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C99DF40C6EC2 for ; Tue, 4 Oct 2022 08:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664872417; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6I7MgN63iSxr6uioLS+tRzCCmN7gydNvOTS8crouyJU=; b=UqMPj4dRCkiBOKO54pSGTlcCBMNrC9V8lGUsigU5eKZ9Mow+vytDOrAQfLuq4NLr9RB2pk MFzItJPuoKrRFEdusv37dS4ToqF3mcPqvFBZ3Ty6bNL4L8felKwBRt1yCbawIBD2sgRtpe tympIl13+V5yqGF2iciMMbROBjaTCrA= X-MC-Unique: D_0c6NEuMASZDd0_rQzxiA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/43] testParseXMLDocFromFile: Refactor control flow Date: Tue, 4 Oct 2022 10:32:45 +0200 Message-Id: <45b119cd4af23a1f374e3a79fcb3a2a02a71b457.1664870258.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664872419186100002 Content-Type: text/plain; charset="utf-8" Move few variables definitions closer to usage, add comments explaining what's happening and simplify the control flow. Signed-off-by: Peter Krempa --- src/test/test_driver.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1c10124564..5740f54a58 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -841,32 +841,34 @@ testDomainObjCheckTaint(virDomainObj *obj) } static xmlNodePtr -testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *typ= e) +testParseXMLDocFromFile(xmlNodePtr node, + const char *file, + const char *type) { - xmlNodePtr ret =3D NULL; g_autoptr(xmlDoc) doc =3D NULL; - g_autofree char *absFile =3D NULL; g_autofree char *relFile =3D NULL; if ((relFile =3D virXMLPropString(node, "file"))) { - absFile =3D testBuildFilename(file, relFile); + g_autofree char *absFile =3D testBuildFilename(file, relFile); + xmlNodePtr newnode =3D NULL; if (!(doc =3D virXMLParse(absFile, NULL, type, NULL, NULL, NULL, f= alse))) return NULL; - ret =3D xmlCopyNode(xmlDocGetRootElement(doc), 1); - if (!ret) { + if (!(newnode =3D xmlCopyNode(xmlDocGetRootElement(doc), 1))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to copy XML node")); return NULL; } - xmlReplaceNode(node, ret); + + /* place 'newnode' in place of 'node' in the original XML document= object */ + xmlReplaceNode(node, newnode); + /* free the original node */ xmlFreeNode(node); - } else { - ret =3D node; + return newnode; } - return ret; + return node; } static int --=20 2.37.3