From nobody Thu Apr 25 07:52:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1630784314; cv=none; d=zohomail.com; s=zohoarc; b=Uv39t127FdpFtV1nws7SSgNyQGeQiu3YqbwHwDV/+zqScH8tKqnwb3jXdPuPK1+6vc0CxSavCVsrdMMRq8e8dED03PAMikeJNCPyPhfq/8CI4fCEp1fRw0/AZbbZS9xxLHzkcK6hPbLNGwls/n1Dxb5SS18//VTihS2LmnzW/do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784314; 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=QyRp5Ah5A4CA5inW9qKSYy4TQwLx/BATfAe8eXGIrjg=; b=XPicbKfnzwfjozx2/JWc40eUiwky6U61Mz9b1bo+OwdI9N4RvnB0lfEPV1ENVt9ytJsXB4xXWXm6uVgHe6fJHKofr1G6ShaXFk9p2Wz5Bv/s9zbdk9jR+U7IzAeGtq6iGnL6QPBCscqyjO38410rdKIsWL/TF1mOGT+aq/s0hmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1630784314100743.7138583309671; Sat, 4 Sep 2021 12:38:34 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-69rOKS10P-S7NXkmQcY6vg-1; Sat, 04 Sep 2021 15:38:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC84F824FAD; Sat, 4 Sep 2021 19:38:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FD8C1000320; Sat, 4 Sep 2021 19:38:26 +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 509FE44A61; Sat, 4 Sep 2021 19:38:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ2al002564 for ; Sat, 4 Sep 2021 15:35:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id E31C2781ED; Sat, 4 Sep 2021 19:35:02 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E81977718 for ; Sat, 4 Sep 2021 19:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784313; 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=QyRp5Ah5A4CA5inW9qKSYy4TQwLx/BATfAe8eXGIrjg=; b=IIMkqhmmRdHSZC29VBkfd6SdHa7FzM44x6vRb0rfIexQDunXTOfx4s1iO7SNBVI7t+iN/l gOdAXQajwyAFJZRMth989DW2Gh2x/ZR+cXSLOpwaftEnu+LKhkDH5OxdTB0+3t7+6K4SPK m1/kWIOg8gXQtkThSNXayffMn61+I+U= X-MC-Unique: 69rOKS10P-S7NXkmQcY6vg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/6] tests: esxutils: refactor testParseDatastorePath Date: Sat, 4 Sep 2021 21:34:47 +0200 Message-Id: <011f2e700583ded58ee965637bfecfa802d64205.1630784040.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784316066100001 Reduce variable scope to match their lifetime, use g_auto and remove now pointless labels in favor of direct returns. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/esxutilstest.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index 2e2020006e..bfb35fa356 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -35,21 +35,17 @@ static struct testPath paths[] =3D { static int testParseDatastorePath(const void *data G_GNUC_UNUSED) { - int result =3D 0; size_t i; - char *datastoreName =3D NULL; - char *directoryName =3D NULL; - char *directoryAndFileName =3D NULL; =20 for (i =3D 0; i < G_N_ELEMENTS(paths); ++i) { - VIR_FREE(datastoreName); - VIR_FREE(directoryName); - VIR_FREE(directoryAndFileName); + g_autofree char *datastoreName =3D NULL; + g_autofree char *directoryName =3D NULL; + g_autofree char *directoryAndFileName =3D NULL; =20 if (esxUtil_ParseDatastorePath (paths[i].datastorePath, &datastoreName, &directoryName, &directoryAndFileName) !=3D paths[i].result) { - goto failure; + return -1; } =20 if (paths[i].result < 0) @@ -57,32 +53,22 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED) =20 if (STRNEQ(paths[i].datastoreName, datastoreName)) { virTestDifference(stderr, paths[i].datastoreName, datastoreNam= e); - goto failure; + return -1; } =20 if (STRNEQ(paths[i].directoryName, directoryName)) { virTestDifference(stderr, paths[i].directoryName, directoryNam= e); - goto failure; + return -1; } =20 if (STRNEQ(paths[i].directoryAndFileName, directoryAndFileName)) { virTestDifference(stderr, paths[i].directoryAndFileName, directoryAndFileName); - goto failure; + return -1; } } =20 - cleanup: - VIR_FREE(datastoreName); - VIR_FREE(directoryName); - VIR_FREE(directoryAndFileName); - - return result; - - failure: - result =3D -1; - - goto cleanup; + return 0; } =20 =20 --=20 2.31.1 From nobody Thu Apr 25 07:52:41 2024 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=1630784112; cv=none; d=zohomail.com; s=zohoarc; b=X4ZaHFK1YkBvBksdzHqhs/Q2CXrFcpLm6Wex8visCqacycN5uct7FaBw7orehofxfig19L9roHSZKXe1xo7D1qwLQmn3HCvaCuJ/doWGIwpyLp6GgPfSV+kYoGRG+Udu/xy7yQwUpUGdJC+78FPA6wVs0Obwh6LdmOIJunnM1PU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784112; 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=nBs2rWro6nV3q7UEgy92Iuq9o33XG7brxMyHG7ZD5H4=; b=JGIaNoh86dUqZYVTM6S+SpL8BK0BWTGhQ08Kej4/xoCOFKQhogcl177K0/9OkgMLZhgUZnw1eyKOY38dm3LEEBLDapSGPG+Koy86/FBzaPe3ZoLJ1DPxht1IIqfynUboAvyO+v64clf2r9c3KzQmdw5iM6cKv0beOMC7Jj/QH1w= 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 1630784112468901.889612608662; Sat, 4 Sep 2021 12:35:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-9BMbyRCJPheigcq0fSe0RA-1; Sat, 04 Sep 2021 15:35:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7D731006719; Sat, 4 Sep 2021 19:35:04 +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 7E04419C59; Sat, 4 Sep 2021 19:35:04 +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 49B21180B44F; Sat, 4 Sep 2021 19:35:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ3oJ002572 for ; Sat, 4 Sep 2021 15:35:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2932781ED; Sat, 4 Sep 2021 19:35:03 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D88E77718 for ; Sat, 4 Sep 2021 19:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784111; 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=nBs2rWro6nV3q7UEgy92Iuq9o33XG7brxMyHG7ZD5H4=; b=MtHfZke5IUf03xJ6mLAOrcE+8GPvpV0jX8Hc+sau5KePQoolzeX9DPvgufPGYU3g5nOSXb 56nxpcR/zhT5b21bwymNZb/OOU8zS4nD0swDNo6bBKAa3yDC2x3DC5w8Gdr9mQsECjrsuD pKxtH3kQydTl2rmok4Rwg3MVN/q86NM= X-MC-Unique: 9BMbyRCJPheigcq0fSe0RA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/6] tests: esxutils: reduce variable scope in testEscapeDatastoreItem Date: Sat, 4 Sep 2021 21:34:48 +0200 Message-Id: <249276c98952329f99ea021e314431c5e2dd0e15.1630784040.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784112730100001 Also use g_auto. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/esxutilstest.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index bfb35fa356..d537da3011 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -161,23 +161,19 @@ static int testEscapeDatastoreItem(const void *data G_GNUC_UNUSED) { size_t i; - char *escaped =3D NULL; =20 for (i =3D 0; i < G_N_ELEMENTS(datastoreItems); ++i) { - VIR_FREE(escaped); + g_autofree char *escaped =3D NULL; =20 escaped =3D esxUtil_EscapeDatastoreItem(datastoreItems[i].string); =20 if (escaped =3D=3D NULL) return -1; =20 - if (STRNEQ(datastoreItems[i].escaped, escaped)) { - VIR_FREE(escaped); + if (STRNEQ(datastoreItems[i].escaped, escaped)) return -1; - } } =20 - VIR_FREE(escaped); return 0; } =20 --=20 2.31.1 From nobody Thu Apr 25 07:52:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1630784115; cv=none; d=zohomail.com; s=zohoarc; b=FbRex/iZuUJaH2kqVyGEbtk6Ida9KboR+aqjUTFqHDlHtaOJ2b4ShmgYi9YJM6fULflQNjPcvg9pQMYRmsmkiY13w5QuwIqBtF0W6qZFlmVarTgOM0k+ovAuV9Ab+fNK85/61HZSnXTeiIefIijO1Xu3uvTRvxLzu9/dsgAa1co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784115; 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=0N8g/2vlOjO0g+oRkE5G40AcmweOzrrf3Q4FhcvX3Hk=; b=A9lLrvwKmYj83m6mDQmKWgbfbnuAtAnT3EuqO7nJftRBtKD53h9dv9NAk9O9nq7uPJVA8i0rgWC+Zdc7zNbefqYk0Yc1paWzymwVWiavvk0g5JaqOy6nvDcjc00EuQ3mJoQpi9WLP51vSiXxwSGwah25bFKSOJatwRFLa/ac32E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1630784115315642.5470638246511; Sat, 4 Sep 2021 12:35:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-YsNAbbAWMbuaJarEo3aEzQ-1; Sat, 04 Sep 2021 15:35:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93DF71854E2A; Sat, 4 Sep 2021 19:35:07 +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 6EA3B19C59; Sat, 4 Sep 2021 19:35:07 +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 4039B180B44F; Sat, 4 Sep 2021 19:35:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ4Mo002579 for ; Sat, 4 Sep 2021 15:35:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83E3C781ED; Sat, 4 Sep 2021 19:35:04 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E7BF77718 for ; Sat, 4 Sep 2021 19:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784114; 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=0N8g/2vlOjO0g+oRkE5G40AcmweOzrrf3Q4FhcvX3Hk=; b=FGzQfNooZ7NChbSOlsmICNusCs+Fx6K/dcr2iGOZnJOl3I7pV1ZqDKGzFWGiEpEeeiIqMq QQ7SM1UEwPgy0q2iF1I1Rm7XQqg92QRXSBhwZXyvSuJhJzp/ilsO1Zs7LQSe+7S+ZK8TL1 uqWqgIRM3qwI3DR4LXW9ofHkqJUZ18o= X-MC-Unique: YsNAbbAWMbuaJarEo3aEzQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/6] tests: esxutils: reduce variable scope in testConvertWindows1252ToUTF8 Date: Sat, 4 Sep 2021 21:34:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784116816100001 Also use g_auto. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/esxutilstest.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index d537da3011..db49dcd6e0 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -197,10 +197,9 @@ static int testConvertWindows1252ToUTF8(const void *data G_GNUC_UNUSED) { size_t i; - char *utf8 =3D NULL; =20 for (i =3D 0; i < G_N_ELEMENTS(windows1252ToUTF8); ++i) { - VIR_FREE(utf8); + g_autofree char *utf8 =3D NULL; =20 utf8 =3D virVMXConvertToUTF8("Windows-1252", windows1252ToUTF8[i].windows1252); @@ -208,13 +207,10 @@ testConvertWindows1252ToUTF8(const void *data G_GNUC_= UNUSED) if (utf8 =3D=3D NULL) return -1; =20 - if (STRNEQ(windows1252ToUTF8[i].utf8, utf8)) { - VIR_FREE(utf8); + if (STRNEQ(windows1252ToUTF8[i].utf8, utf8)) return -1; - } } =20 - VIR_FREE(utf8); return 0; } =20 --=20 2.31.1 From nobody Thu Apr 25 07:52:41 2024 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=1630784118; cv=none; d=zohomail.com; s=zohoarc; b=YsfHf+YDBPDlrNQE4DNLXQ6VwbAsFE692HCIhFn4SeJeIRlMFedn4MaobgURbsOnpgZSKv+ZoO36ULllltdUpdv1e0WZAq0/22Ylqv9AX+A9f89bJ8MYq5NVnyPwz3851Loj0eNqvYNXCdCHKKxA82T2FP3b3pautXCWqgyUJR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784118; 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=8n4nHnZe+joagJ2ShTIDwDX/CfP4jJDVtwx67C/bod0=; b=LtsybVuN17+JLU/JuYAyJ+Pm48W+WWh63dYfLbV4jhwqwZ0T8V7IyVcbo77CHmjJOxJdt7XEJo3eUOZ+E+mWe7vhXBM/9e22xBTv2cPHKMavF0BLyVUI70r2AdIL62mYrcl74iQm1r9n01/bL/7k7f+YLLDiw8ZpuPdMp9RWc/Y= 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 1630784118403523.4770382068072; Sat, 4 Sep 2021 12:35:18 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-IMObCgjYNOetta0nPfL_hA-1; Sat, 04 Sep 2021 15:35:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FD841854E2D; Sat, 4 Sep 2021 19:35:10 +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 2B88C19C59; Sat, 4 Sep 2021 19:35:10 +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 ED7B5180BAA1; Sat, 4 Sep 2021 19:35:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ5XK002592 for ; Sat, 4 Sep 2021 15:35:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5089E77718; Sat, 4 Sep 2021 19:35:05 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF66478433 for ; Sat, 4 Sep 2021 19:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784117; 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=8n4nHnZe+joagJ2ShTIDwDX/CfP4jJDVtwx67C/bod0=; b=MR6rE6PjBzbk6hPAOOH4L/ohYC65lmbvRjBB8FXMcCBeAs0P0JNa+CAP2aq+ZIVIfZmoCM on7KJTmxMOXmJdCX44KpfeDRRvygFvYAoRHa9okXttXNqSyzZs56droBg8/lSrdzAuvobP 0UlfXcJwRwSI6JVbIALKFg6TtSYraYw= X-MC-Unique: IMObCgjYNOetta0nPfL_hA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/6] tests: reduce variable scope in testSELinuxCheckLabels Date: Sat, 4 Sep 2021 21:34:50 +0200 Message-Id: <1e62bd7303ca4f40291b6d2d1d21b0d180caf032.1630784040.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784118983100001 And use g_auto. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/securityselinuxlabeltest.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabelt= est.c index f7dd3c866a..3d886fd827 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -246,10 +246,9 @@ static int testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles) { size_t i; - char *ctx; =20 for (i =3D 0; i < nfiles; i++) { - ctx =3D NULL; + g_autofree char *ctx =3D NULL; if (getfilecon(files[i].file, &ctx) < 0) { if (errno =3D=3D ENODATA) { /* nothing to do */ @@ -266,10 +265,8 @@ testSELinuxCheckLabels(testSELinuxFile *files, size_t = nfiles) virReportError(VIR_ERR_INTERNAL_ERROR, "File %s context '%s' did not match expected '%= s'", files[i].file, ctx, files[i].context); - VIR_FREE(ctx); return -1; } - VIR_FREE(ctx); } return 0; } --=20 2.31.1 From nobody Thu Apr 25 07:52:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1630784319; cv=none; d=zohomail.com; s=zohoarc; b=Zl4YPpWO2gbEvkY0cZu5dle7KubkKo5tAkR9PjQQo6eH/jpoM/Q2s5Rsq3k96ZSz+l/kb11ugqnQPvFI+PMjQg6QvMPA2TvLBfVeH+U7KuqVeg7q2BBRLmVt2f2u3LSQnD+oJzaO/AIvUtywBFyD1ho+Hj6N0SDD2eee6S+JVOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784319; 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=8lSpHXkvN6JDx99T9Tj9QVgKC+D1EnXHwoQuY8YUMEA=; b=NqZypbOlR7DfBt+mJm1K/RxkozrYn3GU4ZhY6HQ6ajB7h5t1z7FSKcPdrqVMlqIBrTtXVoBTZaoIY3xA56ifG1y3YkQSWUTNwJww9OqJApU6IjBczp+Z53QjM2lCbyF7Mt9tOdsnRj6UrKouDgFpffHTvoKVwgAFqXP7ldieoT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1630784319667926.7104951298597; Sat, 4 Sep 2021 12:38:39 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-ykr8AH7zNWiaMRw3TU8r3A-1; Sat, 04 Sep 2021 15:38:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2EBE107ACCD; Sat, 4 Sep 2021 19:38:31 +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 D739C1045D0E; Sat, 4 Sep 2021 19:38:31 +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 A0527180B44F; Sat, 4 Sep 2021 19:38:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ6tL002599 for ; Sat, 4 Sep 2021 15:35:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CAA9781ED; Sat, 4 Sep 2021 19:35:06 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C7BA77718 for ; Sat, 4 Sep 2021 19:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784318; 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=8lSpHXkvN6JDx99T9Tj9QVgKC+D1EnXHwoQuY8YUMEA=; b=I4QQeC5jQyI9oHN9i64OZlpGofTsfE4owHnABwqh6z7w474bj5MWTrhA/5t5wNe3jkYM2X grusFxyjLGalSIAFWyFrncOaegRFD6VuiOUivmTj3obkSjuhSuCRceyd9dKsxk2BPD3zld Yj6NJw/1ZRjoe9a5yInUcOlZKPR09Mg= X-MC-Unique: ykr8AH7zNWiaMRw3TU8r3A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] tests: refactor testSELinuxLoadDef Date: Sat, 4 Sep 2021 21:34:51 +0200 Message-Id: <40ff260392ea7db66b14e7d9b6362b4682ce4dbd.1630784040.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784320199100001 Since its introduction in commit 907a39e735d256b8428ed4c77009d1f713aea19b Add a test suite for validating SELinux labelling this function did not return NULL on OOM. Since we abort on OOM now, switch testSELinuxMungePath to void, return NULL explicitly on XML parsing failure and remove the (now pointless) cleanup label. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/securityselinuxlabeltest.c | 36 +++++++++++--------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabelt= est.c index 3d886fd827..aab1561335 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -83,16 +83,11 @@ testUserXattrEnabled(void) return ret; } =20 -static int +static void testSELinuxMungePath(char **path) { - char *tmp; - - tmp =3D g_strdup_printf("%s/securityselinuxlabeldata%s", abs_builddir,= *path); - - VIR_FREE(*path); - *path =3D tmp; - return 0; + g_free(*path); + *path =3D g_strdup_printf("%s/securityselinuxlabeldata%s", abs_builddi= r, *path); } =20 static int @@ -162,7 +157,7 @@ testSELinuxLoadFileList(const char *testname, static virDomainDef * testSELinuxLoadDef(const char *testname) { - char *xmlfile =3D NULL; + g_autofree char *xmlfile =3D NULL; virDomainDef *def =3D NULL; size_t i; =20 @@ -171,15 +166,14 @@ testSELinuxLoadDef(const char *testname) =20 if (!(def =3D virDomainDefParseFile(xmlfile, driver.xmlopt, NULL, 0))) - goto cleanup; + return NULL; =20 for (i =3D 0; i < def->ndisks; i++) { if (def->disks[i]->src->type !=3D VIR_STORAGE_TYPE_FILE && def->disks[i]->src->type !=3D VIR_STORAGE_TYPE_BLOCK) continue; =20 - if (testSELinuxMungePath(&def->disks[i]->src->path) < 0) - goto cleanup; + testSELinuxMungePath(&def->disks[i]->src->path); } =20 for (i =3D 0; i < def->nserials; i++) { @@ -190,23 +184,17 @@ testSELinuxLoadDef(const char *testname) continue; =20 if (def->serials[i]->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX)= { - if (testSELinuxMungePath(&def->serials[i]->source->data.nix.pa= th) < 0) - goto cleanup; + testSELinuxMungePath(&def->serials[i]->source->data.nix.path); } else { - if (testSELinuxMungePath(&def->serials[i]->source->data.file.p= ath) < 0) - goto cleanup; + testSELinuxMungePath(&def->serials[i]->source->data.file.path); } } =20 - if (def->os.kernel && - testSELinuxMungePath(&def->os.kernel) < 0) - goto cleanup; - if (def->os.initrd && - testSELinuxMungePath(&def->os.initrd) < 0) - goto cleanup; + if (def->os.kernel < 0) + testSELinuxMungePath(&def->os.kernel); + if (def->os.initrd < 0) + testSELinuxMungePath(&def->os.initrd); =20 - cleanup: - VIR_FREE(xmlfile); return def; } =20 --=20 2.31.1 From nobody Thu Apr 25 07:52:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1630784345; cv=none; d=zohomail.com; s=zohoarc; b=MTBp/zH60iZfo1vD3gsq8jqAWb5wmli7dJqV9noidfU4+8cwMaTjg0g+nyE2nEqE7UgXon7ARcwYYU1APYXFPtf9KzXNgMYw+M2lGZNu6VAmHZA1njuuxk2D+aumExlR1YmMTAZEdQT4AQEC5tmbD6rWN+hsuV213e6MrV9zOFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630784345; 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=XhMTrXlpeH7WuuBOJguay5iZnTaMvSBZUEgCww8QgGM=; b=JxZ9GYvaAZem7ssZmRJmNvYf5LW8X5IIU2oRir5mAqcxk/w+Jv399v0ytjMqXF+0TXEuxuYS8ovRtFydv2M61Q2iMtulDtyG8DWPUE8FSJA7mPS6rEc8DVWRURiZ/RC8ppIJoLcltpnKj6CQln27iVdAh8a4WmIzuB3YAutpDBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 163078434557321.003287161733965; Sat, 4 Sep 2021 12:39:05 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-Tu7SZBCTOyyhDDg39RUM2w-1; Sat, 04 Sep 2021 15:38:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F841802B9E; Sat, 4 Sep 2021 19:38:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E834669FC9; Sat, 4 Sep 2021 19:38:06 +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 B810A44A5B; Sat, 4 Sep 2021 19:38:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 184JZ62i002614 for ; Sat, 4 Sep 2021 15:35:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE5B8781EE; Sat, 4 Sep 2021 19:35:06 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 698BB77718 for ; Sat, 4 Sep 2021 19:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630784344; 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=XhMTrXlpeH7WuuBOJguay5iZnTaMvSBZUEgCww8QgGM=; b=DbqXQbcMYRd0FznfLtPLIaBLcecM0v5gAMRl7b/kRFLTMqVBhp6n+BGyMkKHFk/a8xJNYA hv5msaBIFpGVS6Y4pfxsig55TSen3W24XWdmcCpbQrdSxj9qHLfwdVZSjQ78ZDUbNYAzL+ LXH0b+DpuGFa8LayLmms1FXUhNKjXBM= X-MC-Unique: Tu7SZBCTOyyhDDg39RUM2w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 6/6] virnetsockettest: refactor checkProtocols Date: Sat, 4 Sep 2021 21:34:52 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630784346887100003 Reduce variable scope, use g_auto and remove pointless labels. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Pavel Hrdina --- tests/virnetsockettest.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 8059c6cbb0..1de3771ad4 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -47,28 +47,29 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, { struct sockaddr_in in4; struct sockaddr_in6 in6; - int s4 =3D -1, s6 =3D -1; size_t i; - int ret =3D -1; =20 *freePort =3D 0; if (virNetSocketCheckProtocols(hasIPv4, hasIPv6) < 0) return -1; =20 for (i =3D 0; i < 50; i++) { + VIR_AUTOCLOSE s4 =3D -1; + VIR_AUTOCLOSE s6 =3D -1; + if (*hasIPv4) { if ((s4 =3D socket(AF_INET, SOCK_STREAM, 0)) < 0) - goto cleanup; + return -1; } =20 if (*hasIPv6) { int only =3D 1; =20 if ((s6 =3D socket(AF_INET6, SOCK_STREAM, 0)) < 0) - goto cleanup; + return -1; =20 if (setsockopt(s6, IPPROTO_IPV6, IPV6_V6ONLY, &only, sizeof(on= ly)) < 0) - goto cleanup; + return -1; } =20 memset(&in4, 0, sizeof(in4)); @@ -84,22 +85,18 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, if (*hasIPv4) { if (bind(s4, (struct sockaddr *)&in4, sizeof(in4)) < 0) { if (errno =3D=3D EADDRINUSE) { - VIR_FORCE_CLOSE(s4); - VIR_FORCE_CLOSE(s6); continue; } - goto cleanup; + return -1; } } =20 if (*hasIPv6) { if (bind(s6, (struct sockaddr *)&in6, sizeof(in6)) < 0) { if (errno =3D=3D EADDRINUSE) { - VIR_FORCE_CLOSE(s4); - VIR_FORCE_CLOSE(s6); continue; } - goto cleanup; + return -1; } } =20 @@ -109,12 +106,7 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6, =20 VIR_DEBUG("Choose port %d", *freePort); =20 - ret =3D 0; - - cleanup: - VIR_FORCE_CLOSE(s4); - VIR_FORCE_CLOSE(s6); - return ret; + return 0; } =20 struct testClientData { --=20 2.31.1