From nobody Sun Feb 8 16:24:16 2026 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1490192707270766.8593347720317; Wed, 22 Mar 2017 07:25:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2AE98E23C; Wed, 22 Mar 2017 14:25:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 617176292F; Wed, 22 Mar 2017 14:25: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 0445865D34; Wed, 22 Mar 2017 14:25:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2MELjkZ026350 for ; Wed, 22 Mar 2017 10:21:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE9987B8FB; Wed, 22 Mar 2017 14:21:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADAE07B8F3 for ; Wed, 22 Mar 2017 14:21:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A2AE98E23C Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A2AE98E23C From: John Ferlan To: libvir-list@redhat.com Date: Wed, 22 Mar 2017 10:21:22 -0400 Message-Id: <20170322142135.3421-10-jferlan@redhat.com> In-Reply-To: <20170322142135.3421-1-jferlan@redhat.com> References: <20170322142135.3421-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/22] util: Change return argument for virBitmapParseUnlimited 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 22 Mar 2017 14:25:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than returning an int and a *bitmap pointer, just return and check a NULL bitmap pointer Signed-off-by: John Ferlan --- src/util/virbitmap.c | 26 ++++++++++++-------------- src/util/virbitmap.h | 7 +++---- tests/testutils.c | 2 +- tests/virbitmaptest.c | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 1b47d74..d263d73 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -545,7 +545,6 @@ virBitmapParse(const char *str, /** * virBitmapParseUnlimited: * @str: points to a string representing a human-readable bitmap - * @bitmap: a bitmap created from @str * * This function is the counterpart of virBitmapFormat. This function crea= tes * a bitmap, in which bits are set according to the content of @str. @@ -556,20 +555,20 @@ virBitmapParse(const char *str, * to set, and ^N, which means to unset the bit, and N-M for ranges of bits * to set. * - * Returns 0 on success, or -1 in case of error. + * Returns @bitmap on success, or NULL in case of error */ -int -virBitmapParseUnlimited(const char *str, - virBitmapPtr *bitmap) +virBitmapPtr +virBitmapParseUnlimited(const char *str) { + virBitmapPtr bitmap; bool neg =3D false; const char *cur =3D str; char *tmp; size_t i; int start, last; =20 - if (!(*bitmap =3D virBitmapNewEmpty())) - return -1; + if (!(bitmap =3D virBitmapNewEmpty())) + return NULL; =20 if (!str) goto error; @@ -605,10 +604,10 @@ virBitmapParseUnlimited(const char *str, =20 if (*cur =3D=3D ',' || *cur =3D=3D 0) { if (neg) { - if (virBitmapClearBitExpand(*bitmap, start) < 0) + if (virBitmapClearBitExpand(bitmap, start) < 0) goto error; } else { - if (virBitmapSetBitExpand(*bitmap, start) < 0) + if (virBitmapSetBitExpand(bitmap, start) < 0) goto error; } } else if (*cur =3D=3D '-') { @@ -626,7 +625,7 @@ virBitmapParseUnlimited(const char *str, cur =3D tmp; =20 for (i =3D start; i <=3D last; i++) { - if (virBitmapSetBitExpand(*bitmap, i) < 0) + if (virBitmapSetBitExpand(bitmap, i) < 0) goto error; } =20 @@ -644,14 +643,13 @@ virBitmapParseUnlimited(const char *str, } } =20 - return 0; + return bitmap; =20 error: virReportError(VIR_ERR_INVALID_ARG, _("Failed to parse bitmap '%s'"), str); - virBitmapFree(*bitmap); - *bitmap =3D NULL; - return -1; + virBitmapFree(bitmap); + return NULL; } =20 /** diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 58e0ee6..3ba40ae 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -94,10 +94,9 @@ virBitmapParseSeparator(const char *str, char terminator, virBitmapPtr *bitmap, size_t bitmapSize); -int -virBitmapParseUnlimited(const char *str, - virBitmapPtr *bitmap) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +virBitmapPtr +virBitmapParseUnlimited(const char *str) + ATTRIBUTE_NONNULL(1); =20 virBitmapPtr virBitmapNewCopy(virBitmapPtr src) ATTRIBUTE_NONNULL(1); =20 diff --git a/tests/testutils.c b/tests/testutils.c index a596a83..13eff9e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -926,7 +926,7 @@ int virTestMain(int argc, } =20 if ((testRange =3D getenv("VIR_TEST_RANGE")) !=3D NULL) { - if (virBitmapParseUnlimited(testRange, &testBitmap) < 0) { + if (!(testBitmap =3D virBitmapParseUnlimited(testRange))) { fprintf(stderr, "Cannot parse range %s\n", testRange); return EXIT_FAILURE; } diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 3ee07ff..e007efc 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -650,7 +650,7 @@ test12(const void *opaque ATTRIBUTE_UNUSED) TEST_MAP(151, "128"); =20 virBitmapFree(map); - if (virBitmapParseUnlimited("34,1023", &map) < 0) + if (!(map =3D virBitmapParseUnlimited("34,1023"))) goto cleanup; =20 TEST_MAP(1024, "34,1023"); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list