From nobody Mon Feb 9 01:06:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1601624632; cv=none; d=zohomail.com; s=zohoarc; b=QbgLf3F5Z88xc6ruo0VrTWJM6IYXDVORptMLk431D5eW9FyeO9jaJGKwtbD6lkaXvkGgnIsCpaZTf8xc6EX9VDvUAnjCmxMRVt3xWkARanE6DTJYQSERsSxzzipbiN2I6iRtazRmKA1ettIeU4mc1sq94fyoTxBRLzK84rtPHig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624632; 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=EgrVa5FufvDEf0bLIfn/2nSDTaKCePzMmsrK6aiSkRU=; b=hBhF2Zl3uimVlE92AUWn26mC8A4DUmIpZIn/cYXLmqThSHzSbmvdLTNk8o7eNPVuv/OQJ5tRddk4Qt5eTksxF3Y69FoubWbs2EGL32EAcSl/IEFLDrQSvmcUWz2QWcR4d/Ew6+C/DvLmsNUyrYTOsoLSKgXe9ZwLWmFuYyFjflI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601624632689650.3450366960494; Fri, 2 Oct 2020 00:43:52 -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-134-M1VY1ssPOs628USv5CqpXw-1; Fri, 02 Oct 2020 03:43:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC945188C125; Fri, 2 Oct 2020 07:43:42 +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 9DA3373685; Fri, 2 Oct 2020 07:43:42 +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 6C7DC44A6E; Fri, 2 Oct 2020 07:43:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0927hMNc004166 for ; Fri, 2 Oct 2020 03:43:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2A991972A; Fri, 2 Oct 2020 07:43:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1323B19931 for ; Fri, 2 Oct 2020 07:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624631; 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=EgrVa5FufvDEf0bLIfn/2nSDTaKCePzMmsrK6aiSkRU=; b=MeS91S6d/kDfRMPKvOxQraw4BDanKkIxMpVJY6haea+hVG64bhvzbU9IoKabZqeqcRUrrI rZZI78Lz/a9oR6VjvcUKpYV4tpQA23q423oHUSK9NOFDYfLbBpraZfaK+Xfx/PxBjlYjdV MrWkkrg3ckYEKgPBaqxfpmvQBJp8tCA= X-MC-Unique: M1VY1ssPOs628USv5CqpXw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/15] virbitmaptest: Remove unnecessary error/cleanup labels Date: Fri, 2 Oct 2020 09:43:01 +0200 Message-Id: <6370d60bd249be547a4a841496f37d3778b92d32.1601624533.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.13 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbitmaptest.c | 264 +++++++++++++++++------------------------- 1 file changed, 108 insertions(+), 156 deletions(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index bfca208a7f..56110971c9 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -33,32 +33,28 @@ test1(const void *data G_GNUC_UNUSED) int size; int bit; bool result; - int ret =3D -1; size =3D 1024; bit =3D 100; if (!(bitmap =3D virBitmapNew(size))) - goto error; + return -1; if (virBitmapSetBit(bitmap, bit) < 0) - goto error; + return -1; if (virBitmapGetBit(bitmap, bit, &result) < 0) - goto error; + return -1; if (!result) - goto error; + return -1; if (virBitmapGetBit(bitmap, bit + 1, &result) < 0) - goto error; + return -1; if (result) - goto error; - - ret =3D 0; + return -1; - error: - return ret; + return 0; } static int @@ -86,85 +82,78 @@ test2(const void *data G_GNUC_UNUSED) const char *bitsString1 =3D "1-32,50,88-99,1021-1023"; g_autofree char *bitsString2 =3D NULL; g_autoptr(virBitmap) bitmap =3D NULL; - int ret =3D -1; int size =3D 1025; if (virBitmapParse(bitsString1, &bitmap, size) < 0) - goto error; + return -1; if (testBit(bitmap, 1, 32, true) < 0) - goto error; + return -1; if (testBit(bitmap, 50, 50, true) < 0) - goto error; + return -1; if (testBit(bitmap, 88, 99, true) < 0) - goto error; + return -1; if (testBit(bitmap, 1021, 1023, true) < 0) - goto error; + return -1; if (testBit(bitmap, 0, 0, false) < 0) - goto error; + return -1; if (testBit(bitmap, 33, 49, false) < 0) - goto error; + return -1; if (testBit(bitmap, 51, 87, false) < 0) - goto error; + return -1; if (testBit(bitmap, 100, 1020, false) < 0) - goto error; + return -1; if (virBitmapCountBits(bitmap) !=3D 48) - goto error; + return -1; if (!(bitsString2 =3D virBitmapFormat(bitmap))) - goto error; + return -1; if (strcmp(bitsString1, bitsString2)) - goto error; + return -1; virBitmapSetAll(bitmap); if (testBit(bitmap, 0, size - 1, true) < 0) - goto error; + return -1; if (virBitmapCountBits(bitmap) !=3D size) - goto error; + return -1; if (!virBitmapIsAllSet(bitmap)) - goto error; + return -1; virBitmapClearAll(bitmap); if (!virBitmapIsAllClear(bitmap)) - goto error; + return -1; if (testBit(bitmap, 0, size - 1, false) < 0) - goto error; + return -1; if (virBitmapCountBits(bitmap) !=3D 0) - goto error; - - ret =3D 0; + return -1; - error: - return ret; + return 0; } static int test3(const void *data G_GNUC_UNUSED) { g_autoptr(virBitmap) bitmap =3D NULL; - int ret =3D -1; int size =3D 5; size_t i; if ((bitmap =3D virBitmapNew(size)) =3D=3D NULL) - goto error; + return -1; for (i =3D 0; i < size; i++) ignore_value(virBitmapSetBit(bitmap, i)); if (!virBitmapIsAllSet(bitmap)) - goto error; + return -1; virBitmapClearAll(bitmap); if (!virBitmapIsAllClear(bitmap)) - goto error; - ret =3D 0; + return -1; - error: - return ret; + return 0; } /* test for virBitmapNextSetBit, virBitmapLastSetBit, virBitmapNextClearBi= t */ @@ -185,20 +174,20 @@ test4(const void *data G_GNUC_UNUSED) ssize_t i, j; if (G_N_ELEMENTS(bitsPos) + G_N_ELEMENTS(bitsPosInv) !=3D size) - goto error; + return -1; /* 0. empty set */ bitmap =3D virBitmapNewEmpty(); if (virBitmapNextSetBit(bitmap, -1) !=3D -1) - goto error; + return -1; if (virBitmapLastSetBit(bitmap) !=3D -1) - goto error; + return -1; if (virBitmapNextClearBit(bitmap, -1) !=3D -1) - goto error; + return -1; virBitmapFree(bitmap); bitmap =3D NULL; @@ -207,23 +196,23 @@ test4(const void *data G_GNUC_UNUSED) bitmap =3D virBitmapNew(size); if (!bitmap) - goto error; + return -1; if (virBitmapNextSetBit(bitmap, -1) !=3D -1) - goto error; + return -1; if (virBitmapLastSetBit(bitmap) !=3D -1) - goto error; + return -1; for (i =3D 0; i < size; i++) { if (virBitmapNextClearBit(bitmap, i - 1) !=3D i) - goto error; + return -1; } if (virBitmapNextClearBit(bitmap, i) !=3D -1) - goto error; + return -1; if (!virBitmapIsAllClear(bitmap)) - goto error; + return -1; virBitmapFree(bitmap); bitmap =3D NULL; @@ -231,9 +220,9 @@ test4(const void *data G_GNUC_UNUSED) /* 2. partial set */ if (virBitmapParse(bitsString, &bitmap, size) < 0) - goto error; + return -1; if (!bitmap) - goto error; + return -1; j =3D 0; i =3D -1; @@ -241,16 +230,16 @@ test4(const void *data G_GNUC_UNUSED) while (j < G_N_ELEMENTS(bitsPos)) { i =3D virBitmapNextSetBit(bitmap, i); if (i !=3D bitsPos[j++]) - goto error; + return -1; } if (virBitmapNextSetBit(bitmap, i) !=3D -1) - goto error; + return -1; j =3D sizeof(bitsPos)/sizeof(int) - 1; if (virBitmapLastSetBit(bitmap) !=3D bitsPos[j]) - goto error; + return -1; j =3D 0; i =3D -1; @@ -258,11 +247,11 @@ test4(const void *data G_GNUC_UNUSED) while (j < G_N_ELEMENTS(bitsPosInv)) { i =3D virBitmapNextClearBit(bitmap, i); if (i !=3D bitsPosInv[j++]) - goto error; + return -1; } if (virBitmapNextClearBit(bitmap, i) !=3D -1) - goto error; + return -1; /* 3. full set */ @@ -270,21 +259,18 @@ test4(const void *data G_GNUC_UNUSED) for (i =3D 0; i < size; i++) { if (virBitmapNextSetBit(bitmap, i - 1) !=3D i) - goto error; + return -1; } if (virBitmapNextSetBit(bitmap, i) !=3D -1) - goto error; + return -1; if (virBitmapLastSetBit(bitmap) !=3D size - 1) - goto error; + return -1; if (virBitmapNextClearBit(bitmap, -1) !=3D -1) - goto error; + return -1; return 0; - - error: - return -1; } /* test for virBitmapNewData/ToData/DataFormat */ @@ -298,28 +284,27 @@ test5(const void *v G_GNUC_UNUSED) g_autoptr(virBitmap) bitmap =3D NULL; size_t i; ssize_t j; - int ret =3D -1; g_autofree char *str =3D NULL; bitmap =3D virBitmapNewData(data, sizeof(data)); if (!bitmap) - goto error; + return -1; i =3D 0; j =3D -1; while (i < sizeof(bits)/sizeof(int) && (j =3D virBitmapNextSetBit(bitmap, j)) >=3D 0) { if (j !=3D bits[i++]) - goto error; + return -1; } if (virBitmapNextSetBit(bitmap, j) > 0) - goto error; + return -1; ignore_value(virBitmapSetBit(bitmap, 2)); ignore_value(virBitmapSetBit(bitmap, 15)); if (virBitmapToData(bitmap, &data2, &len2) < 0) - goto error; + return -1; if (len2 !=3D sizeof(data) || data2[0] !=3D 0x05 || @@ -327,21 +312,19 @@ test5(const void *v G_GNUC_UNUSED) data2[2] !=3D 0x00 || data2[3] !=3D 0x00 || data2[4] !=3D 0x04) - goto error; + return -1; if (!(str =3D virBitmapDataFormat(data, sizeof(data)))) - goto error; + return -1; if (STRNEQ(str, "0,9,34")) - goto error; + return -1; VIR_FREE(str); if (!(str =3D virBitmapDataFormat(data2, len2))) - goto error; + return -1; if (STRNEQ(str, "0,2,9,15,34")) - goto error; + return -1; - ret =3D 0; - error: - return ret; + return 0; } @@ -352,28 +335,27 @@ test6(const void *v G_GNUC_UNUSED) g_autoptr(virBitmap) bitmap =3D NULL; g_autofree char *str =3D NULL; int size =3D 64; - int ret =3D -1; bitmap =3D virBitmapNew(size); if (!bitmap) - goto error; + return -1; str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "")) - goto error; + return -1; VIR_FREE(str); ignore_value(virBitmapSetBit(bitmap, 0)); str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "0")) - goto error; + return -1; VIR_FREE(str); @@ -381,20 +363,20 @@ test6(const void *v G_GNUC_UNUSED) ignore_value(virBitmapSetBit(bitmap, 5)); str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "0,4-5")) - goto error; + return -1; VIR_FREE(str); ignore_value(virBitmapSetBit(bitmap, 6)); str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "0,4-6")) - goto error; + return -1; VIR_FREE(str); @@ -404,10 +386,10 @@ test6(const void *v G_GNUC_UNUSED) ignore_value(virBitmapSetBit(bitmap, 16)); str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "0,4-6,13-16")) - goto error; + return -1; VIR_FREE(str); @@ -415,15 +397,12 @@ test6(const void *v G_GNUC_UNUSED) ignore_value(virBitmapSetBit(bitmap, 63)); str =3D virBitmapFormat(bitmap); if (!str) - goto error; + return -1; if (STRNEQ(str, "0,4-6,13-16,62-63")) - goto error; - + return -1; - ret =3D 0; - error: - return ret; + return 0; } static int @@ -438,28 +417,25 @@ test7(const void *v G_GNUC_UNUSED) for (i =3D 0; i < nmaxBit; i++) { g_autoptr(virBitmap) bitmap =3D virBitmapNew(maxBit[i]); if (!bitmap) - goto error; + return -1; if (virBitmapIsAllSet(bitmap)) - goto error; + return -1; ignore_value(virBitmapSetBit(bitmap, 1)); if (virBitmapIsAllSet(bitmap)) - goto error; + return -1; virBitmapSetAll(bitmap); if (!virBitmapIsAllSet(bitmap)) - goto error; + return -1; virBitmapClearAll(bitmap); if (!virBitmapIsAllClear(bitmap)) - goto error; + return -1; } return 0; - - error: - return -1; } static int @@ -467,24 +443,21 @@ test8(const void *v G_GNUC_UNUSED) { g_autoptr(virBitmap) bitmap =3D NULL; char data[108] =3D {0x00,}; - int ret =3D -1; bitmap =3D virBitmapNewData(data, sizeof(data)); if (!bitmap) - goto cleanup; + return -1; if (!virBitmapIsAllClear(bitmap)) - goto cleanup; + return -1; if (virBitmapSetBit(bitmap, 11) < 0) - goto cleanup; + return -1; if (virBitmapIsAllClear(bitmap)) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } @@ -492,37 +465,32 @@ test8(const void *v G_GNUC_UNUSED) static int test9(const void *opaque G_GNUC_UNUSED) { - int ret =3D -1; g_autoptr(virBitmap) bitmap =3D NULL; if (virBitmapParse("100000000", &bitmap, 20) !=3D -1) - goto cleanup; + return -1; if (bitmap) - goto cleanup; + return -1; if (virBitmapParse("1-1000000000", &bitmap, 20) !=3D -1) - goto cleanup; + return -1; if (bitmap) - goto cleanup; + return -1; if (virBitmapParse("1-10^10000000000", &bitmap, 20) !=3D -1) - goto cleanup; + return -1; if (bitmap) - goto cleanup; - - ret =3D 0; - cleanup: - return ret; + return -1; + return 0; } static int test10(const void *opaque G_GNUC_UNUSED) { - int ret =3D -1; g_autoptr(virBitmap) b1 =3D NULL; g_autoptr(virBitmap) b2 =3D NULL; g_autoptr(virBitmap) b3 =3D NULL; @@ -532,10 +500,10 @@ test10(const void *opaque G_GNUC_UNUSED) virBitmapParse("4,9,10,16-19", &b2, 20) < 0 || virBitmapParse("15", &b3, 20) < 0 || virBitmapParse("0,^0", &b4, 20) < 0) - goto cleanup; + return -1; if (!virBitmapIsAllClear(b4)) - goto cleanup; + return -1; if (virBitmapOverlaps(b1, b2) || virBitmapOverlaps(b1, b4) || @@ -543,11 +511,9 @@ test10(const void *opaque G_GNUC_UNUSED) virBitmapOverlaps(b2, b4) || !virBitmapOverlaps(b1, b3) || virBitmapOverlaps(b3, b4)) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } struct testBinaryOpData { @@ -563,12 +529,11 @@ test11(const void *opaque) g_autoptr(virBitmap) amap =3D NULL; g_autoptr(virBitmap) bmap =3D NULL; g_autoptr(virBitmap) resmap =3D NULL; - int ret =3D -1; if (virBitmapParse(data->a, &amap, 256) < 0 || virBitmapParse(data->b, &bmap, 256) < 0 || virBitmapParse(data->res, &resmap, 256) < 0) - goto cleanup; + return -1; virBitmapIntersect(amap, bmap); @@ -576,14 +541,10 @@ test11(const void *opaque) fprintf(stderr, "\n bitmap intersection failed: intersect('%s','%s') !=3D'= %s'\n", data->a, data->b, data->res); - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - - return ret; + return 0; } #define TEST_MAP(sz, expect) \ @@ -592,7 +553,7 @@ test11(const void *opaque) if (virBitmapSize(map) !=3D sz) { \ fprintf(stderr, "\n expected bitmap size: '%d' actual size: " \ "'%zu'\n", sz, virBitmapSize(map)); \ - goto cleanup; \ + return -1; \ } \ \ actual =3D virBitmapFormat(map); \ @@ -601,7 +562,7 @@ test11(const void *opaque) fprintf(stderr, "\n expected bitmap contents '%s' actual conte= nts "\ "'%s'\n", NULLSTR(expect), NULLSTR(actual)); \ VIR_FREE(actual); \ - goto cleanup; \ + return -1; \ } \ VIR_FREE(actual); \ } while (0) @@ -611,23 +572,22 @@ static int test12(const void *opaque G_GNUC_UNUSED) { g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); - int ret =3D -1; TEST_MAP(0, ""); if (virBitmapSetBitExpand(map, 128) < 0) - goto cleanup; + return -1; TEST_MAP(129, "128"); if (virBitmapClearBitExpand(map, 150) < 0) - goto cleanup; + return -1; TEST_MAP(151, "128"); virBitmapFree(map); if (!(map =3D virBitmapParseUnlimited("34,1023"))) - goto cleanup; + return -1; TEST_MAP(1024, "34,1023"); @@ -637,10 +597,7 @@ test12(const void *opaque G_GNUC_UNUSED) virBitmapShrink(map, 34); TEST_MAP(34, ""); - ret =3D 0; - - cleanup: - return ret; + return 0; } @@ -680,12 +637,11 @@ test14(const void *opaque) g_autoptr(virBitmap) amap =3D NULL; g_autoptr(virBitmap) bmap =3D NULL; g_autoptr(virBitmap) resmap =3D NULL; - int ret =3D -1; if (virBitmapParse(data->a, &amap, 256) < 0 || virBitmapParse(data->b, &bmap, 256) < 0 || virBitmapParse(data->res, &resmap, 256) < 0) - goto cleanup; + return -1; virBitmapSubtract(amap, bmap); @@ -693,14 +649,10 @@ test14(const void *opaque) fprintf(stderr, "\n bitmap subtraction failed: '%s' - '%s' !=3D '%s'\n", data->a, data->b, data->res); - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - - return ret; + return 0; } /* virBitmapUnion() */ --=20 2.26.2