From nobody Mon Apr 29 21:56:55 2024 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=1601624614; cv=none; d=zohomail.com; s=zohoarc; b=NbR3uQjHUgQzpiB6b/tNGb7fKgMFbhqG2svtePQwsigjnBPr4H4OpaV3yL0S99mUbss/tGNpTIIqs26N6iiDS8r79uFnbXpGESct7CdepmFDT+c6hWadwddYpkLrUsb699tbQ/1pq9lSos5uBS/To+XRD3dPcVrzN4dhATRfgZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624614; 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=77bC4jrprmi1R1ovkxQE0gR8RmO+gy51t//6/TAFhhU=; b=OaCd/NPcR0XpLqm3tetSTZcxaLzic109k/job6TcrmlIlCMh10Ymy/HJBXIH5azSO31LAleIv8HNnkJ56SQ44ftTiHgwGelDSnhdcCGJq3d+qiOuPhUNRsnTODENyGV9bpEIG3Ti5ZDnT+JsfU2zE822p7K7M+t4i9GUMlZFxm0= 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 160162461449994.76687740652778; Fri, 2 Oct 2020 00:43: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-258-iArBKUb_OJGe-ZZNwBuOgQ-1; Fri, 02 Oct 2020 03:43:29 -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 E49BA1882FCF; Fri, 2 Oct 2020 07:43:23 +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 C594010023A5; Fri, 2 Oct 2020 07:43:23 +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 94EC744A44; Fri, 2 Oct 2020 07:43:23 +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 0927hG70004093 for ; Fri, 2 Oct 2020 03:43:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C1BD19931; Fri, 2 Oct 2020 07:43:16 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF891992F for ; Fri, 2 Oct 2020 07:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624611; 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=77bC4jrprmi1R1ovkxQE0gR8RmO+gy51t//6/TAFhhU=; b=UKC+iQCkwbW2XtZJ97Ls1F60anDOh7WQwslnLVD+okvAPyvCM8GxVCA9PnF076nW+rNy4u jFvOX/IXfjV/imnCKNfcqv4M4hB9eLPP7ooaB5IWk7FTnUSRNTv+sNm5s0R94my0bK4kFe 1CTaWxa2j0hV09J/dfPATB9Cufs8mjY= X-MC-Unique: iArBKUb_OJGe-ZZNwBuOgQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/15] virQEMUCapsFlagsString: Remove unused function Date: Fri, 2 Oct 2020 09:42:55 +0200 Message-Id: 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.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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Unused since a7424faff0fe8270c18d5e9e3befcfd2822d421f Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 6 ------ src/qemu/qemu_capabilities.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 5dcfcd574d..ea2e4c0948 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2035,12 +2035,6 @@ virQEMUCapsClear(virQEMUCapsPtr qemuCaps, } -char *virQEMUCapsFlagsString(virQEMUCapsPtr qemuCaps) -{ - return virBitmapToString(qemuCaps->flags, true, false); -} - - bool virQEMUCapsGet(virQEMUCapsPtr qemuCaps, virQEMUCapsFlags flag) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 98d70cfa0e..107056ba17 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -611,8 +611,6 @@ bool virQEMUCapsHasPCIMultiBus(virQEMUCapsPtr qemuCaps, bool virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps, const virDomainDef *def); -char *virQEMUCapsFlagsString(virQEMUCapsPtr qemuCaps); - const char *virQEMUCapsGetBinary(virQEMUCapsPtr qemuCaps); virArch virQEMUCapsGetArch(virQEMUCapsPtr qemuCaps); unsigned int virQEMUCapsGetVersion(virQEMUCapsPtr qemuCaps); --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624615; cv=none; d=zohomail.com; s=zohoarc; b=MY3kI8e8PVdXVsCNN7NNVruRkwl6riT4zMLVDs+iDK8F9plPg+F7C6/gQ8XcTxu3MrSXB2Wxw4BTytmsseMynpwL5igl7IChe1Zp7u3zF0ajd0nn1NcKLVI0x3xg2mOtkdC0u0/FwXz9Ljou+w70R9ysdeC3gz2J0WMZuNl3iE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624615; 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=UhUgj89OZ8Z8GESRSNIDYzoS7smWx6XKFbX3HYKx9lY=; b=GXOpLK9K5OBvM5f7YFzl2XaD1Gt3UM07WIG3FJwiXxYE4p8MbOI1kIeILNn3PgXZ3wrQgRx2w0HgBNmkKRX8a4OKCxkoD6wE1d/LyqXT7ImckpP/zzwJ0S3cSwgmB5NU4fTTrCGd3OeS2gOsqBGK4FHwSSIMc+stpf2OsEAk8Eg= 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 1601624615290772.8710152759279; Fri, 2 Oct 2020 00:43:35 -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-466-1co79bylN86ThlJYrE3hUw-1; Fri, 02 Oct 2020 03:43:29 -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 00E46100A8F7; Fri, 2 Oct 2020 07:43:23 +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 A06081992F; Fri, 2 Oct 2020 07:43:21 +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 AD37844A41; Fri, 2 Oct 2020 07:43:18 +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 0927hH6R004099 for ; Fri, 2 Oct 2020 03:43:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4BB1519931; Fri, 2 Oct 2020 07:43:17 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E5991992F for ; Fri, 2 Oct 2020 07:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624611; 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=UhUgj89OZ8Z8GESRSNIDYzoS7smWx6XKFbX3HYKx9lY=; b=e+sTUb7F51BEq1Hk+sY2q6xiSjbaiRMR5wseL8EY8P7Am4V3g3AYgVgv6tciirSFTpMhr2 xiwMhun2B/H0VNXlV92O+F4LD4TXiBD/3IWA+LiIbMLDFpsNsb6WokRUUQQ7TEcOPWQUnO /ONTY8Ajf9VoNuvLoAIJ7J5YJ8EFbdo= X-MC-Unique: 1co79bylN86ThlJYrE3hUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/15] virBitmapToString: Remove unused 'prefix' and 'trim' arguments Date: Fri, 2 Oct 2020 09:42:56 +0200 Message-Id: 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.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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There's only one combination used so we can remove the rest. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 15 +-------------- src/util/virbitmap.h | 2 +- src/util/virresctrl.c | 2 +- tests/virbitmaptest.c | 2 +- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 639103e518..ad5213f216 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -327,17 +327,13 @@ virBitmapGetBit(virBitmapPtr bitmap, /** * virBitmapToString: * @bitmap: Pointer to bitmap - * @prefix: Whether to prepend "0x" - * @trim: Whether to output only the minimum required characters * * Convert @bitmap to printable string. * * Returns pointer to the string or NULL on error. */ char * -virBitmapToString(virBitmapPtr bitmap, - bool prefix, - bool trim) +virBitmapToString(virBitmapPtr bitmap) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; size_t sz; @@ -345,9 +341,6 @@ virBitmapToString(virBitmapPtr bitmap, size_t diff; char *ret =3D NULL; - if (prefix) - virBufferAddLit(&buf, "0x"); - sz =3D bitmap->map_len; while (sz--) { @@ -360,15 +353,9 @@ virBitmapToString(virBitmapPtr bitmap, if (!ret) return NULL; - if (!trim) - return ret; - if (bitmap->nbits !=3D bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT) { char *tmp =3D ret; - if (prefix) - tmp +=3D 2; - len =3D strlen(tmp); sz =3D VIR_DIV_UP(bitmap->nbits, 4); diff =3D len - sz; diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 7f1a109c01..615ec6e4af 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -81,7 +81,7 @@ virBitmapPtr virBitmapNewString(const char *string) ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; -char *virBitmapToString(virBitmapPtr bitmap, bool prefix, bool trim) +char *virBitmapToString(virBitmapPtr bitmap) ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; char *virBitmapFormat(virBitmapPtr bitmap); diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 6de700a645..2d945ff934 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1592,7 +1592,7 @@ virResctrlAllocFormatCache(virResctrlAllocPtr alloc, if (!mask) continue; - mask_str =3D virBitmapToString(mask, false, true); + mask_str =3D virBitmapToString(mask); if (!mask_str) return -1; diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 1c7dc1d610..e1a49bfe35 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -681,7 +681,7 @@ test13(const void *opaque G_GNUC_UNUSED) if (!map) goto cleanup; - str =3D virBitmapToString(map, false, true); + str =3D virBitmapToString(map); if (!str) goto cleanup; --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624628; cv=none; d=zohomail.com; s=zohoarc; b=NoUUXzRKgDktBZ5TdTKHvGZ0TQgXMkQnj/pT+VxVOXpjOKj03s23e3WPhIQrkOtKK03jnAds57eeSljeXpsTb6i2M/sq+TofLXrWqmyR9NZP1Gn+sYzvkNm1zBMNffMNpz3+C0BCBY/94wJnrkhjOoMFTPAzigwJoAWHjXm1oVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624628; 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=VfV3YmAqEwoll4QWaCVRaqu+wh3a9BX4fb5sPkBWGOs=; b=FNKBUl2yBi3hrM+uvb/yZ9IWa+fAeKi5NeKXMQ52uCaYZK/pWJcjuzS6JGnzG9/I5Husz2ww2hQqJqUXmuhuAep298WPCtET44rwWZj+8jkIYJZFCZngkrzlptQiMK0b6SBvUTmhUGvpDy0hdcGf1GWIJhk9ivFH5pM5eAapSEQ= 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 1601624628498564.1949856917695; Fri, 2 Oct 2020 00:43:48 -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-146-2gObi4X3MSqWRkZKz5_wXQ-1; Fri, 02 Oct 2020 03:43:42 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 724AF6408C; Fri, 2 Oct 2020 07:43:37 +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 51FE45C1D0; Fri, 2 Oct 2020 07:43:37 +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 2240B180B791; Fri, 2 Oct 2020 07:43:37 +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 0927hIli004107 for ; Fri, 2 Oct 2020 03:43:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4EBC51992F; Fri, 2 Oct 2020 07:43:18 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF8A91A4D6 for ; Fri, 2 Oct 2020 07:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624625; 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=VfV3YmAqEwoll4QWaCVRaqu+wh3a9BX4fb5sPkBWGOs=; b=BPGIhTa28mM62ug/jqiO4CP5okJqJuu881Y8YM6Eu01JX+OZt3KhkXW2CDxPS3q4oeQOFq qm96+AbuRrgWbstAy/k432DpluybcA+LacNCzjQl7gTlb9eGTY4ehPMg6FN7T/buA+q/nz B2CZbcJ4ZELBbSL+/d0O5Q/J2R6drg0= X-MC-Unique: 2gObi4X3MSqWRkZKz5_wXQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/15] virBitmapToString|virBitmapNewString: Clarify semantics of the 'string' Date: Fri, 2 Oct 2020 09:42:57 +0200 Message-Id: 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.16 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" Clarify which bit is considered most significant in the bitmap and resulting string. Also be explicit that it's a hex string. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index ad5213f216..fcb8e1101a 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -328,7 +328,9 @@ virBitmapGetBit(virBitmapPtr bitmap, * virBitmapToString: * @bitmap: Pointer to bitmap * - * Convert @bitmap to printable string. + * Convert @bitmap to printable hexadecimal string representation. Note th= at bit + * with highest position/index in @bitmap are considered as most significa= nt bit + * in the output string. * * Returns pointer to the string or NULL on error. */ @@ -1117,10 +1119,13 @@ virBitmapCountBits(virBitmapPtr bitmap) * virBitmapNewString: * @string: the string to be converted to a bitmap * - * Allocate a bitmap from a string of hexadecimal data. + * Allocate a bitmap and populate it from a string of hexadecimal data. No= te + * that leftmost character in the string will correspond to the highest + * index/position in the bitmap. The size of the returned bitmap correspon= ds to + * 4 * the length of @string. * - * Returns a pointer to the allocated bitmap or NULL if - * memory cannot be allocated. + * Returns a pointer to the allocated bitmap or NULL and reports an error = if + * @string can't be converted. */ virBitmapPtr virBitmapNewString(const char *string) --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624628; cv=none; d=zohomail.com; s=zohoarc; b=g37bUUQZJn1pGbNytcZJczfK30WpOE+kKYvOJOeL+B+1c0SL/abLKw3MmIJ0ceKQResHIxCoAm0k91qsoGY+FGsiF4IP8LCcaK/FrOZExmeN29WvDnx9n4NRmOpEEevvsj0roY9YZk81zrUQRt1qnLkjKqPzFaS8Z1+5dLgXyyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624628; 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=Gt0WWX1U3dlRTHYXN38QduVecVbD2cVKBqEuTjxkKUw=; b=fFfctia047bzl5s/hYq09qfYzBYWcNy84MAARMGhYgGwJS8AVH73Fmd8kicrZ78njljLSTBkVRR7wySxTLczhCafUnze9de1QXlMIYcLH7mIaHGJhJ0xxlFwVbouKUK4EfQky8dlXdx95u2UCbAwEBTfZ7GAQBmj0I689aXGkWo= 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 1601624628137433.77612798550274; Fri, 2 Oct 2020 00:43:48 -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-520-AHEyPYApP0uyFsIliyXwPQ-1; Fri, 02 Oct 2020 03:43:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F3D410BBEF1; Fri, 2 Oct 2020 07:43:36 +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 7E2DC5D9D5; Fri, 2 Oct 2020 07:43:36 +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 4C8C7180B658; Fri, 2 Oct 2020 07:43:36 +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 0927hJfN004128 for ; Fri, 2 Oct 2020 03:43:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 64C2919931; Fri, 2 Oct 2020 07:43:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC7361992F for ; Fri, 2 Oct 2020 07:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624623; 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=Gt0WWX1U3dlRTHYXN38QduVecVbD2cVKBqEuTjxkKUw=; b=aJqYmfHu9IhwzqQr8NriSot51KYaFUnDq92StHx/lPVWSQ4FyWnGUuwTLwBvrmvtifBAIe lGL5FgThjeHnShpp7PQe2Px7SEUOpvBH4T/5FgcrQ2cx6APUSwWxogdbdO9X0zqDa/3JUT 9ekL903w2BLHWtE8CDt/N0sjPwWXsGw= X-MC-Unique: AHEyPYApP0uyFsIliyXwPQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/15] virBitmapToString: Properly handle empty bitmaps Date: Fri, 2 Oct 2020 09:42:58 +0200 Message-Id: <67b37320576156d0c0d221b9964f659ff3386fe6.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.14 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" virBitmapNewEmpty() can create a bitmap with 0 lenght. With such a bitmap virBitmapToString will return NULL rather than an empty string. Initialize the buffer to avoid that. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index fcb8e1101a..f1443c3ecf 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -345,6 +345,9 @@ virBitmapToString(virBitmapPtr bitmap) sz =3D bitmap->map_len; + /* initialize buffer to return empty string for 0 length bitmap */ + virBufferAdd(&buf, "", -1); + while (sz--) { virBufferAsprintf(&buf, "%0*lx", VIR_BITMAP_BITS_PER_UNIT / 4, --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624629; cv=none; d=zohomail.com; s=zohoarc; b=LwYR9k0XtRcEGNS6ZkXHPzCmF2s9w+WQmGroBdyxUkVSkzoVfOwvyJWZkvrd51ky4fGTgou6a0YoqUMV4HWBV/yFJ/kCtt31FvBzXwnmkxOElO3jTgqVoZEA5dethVkWtxqIc+5a5HhYtlQLFkMcY1fygZWwWDf+m/2vCRK3oRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624629; 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=szv4glwUfHBXZl6FhBS+Ch6qPH8kS0h+OBwgJ/dMxD0=; b=BY9YsiOdq+WLLtFMQ9UwsYKto/lE1NGOs2EvWEGcbhZ/93UdFCsxM8hN9Ydkc8gdc9GNMNgFchAu//jFv8/QAEQqCYD4thAtFcfkLkdzt6/7rxVgvlaErR3Ql44Uc2fXP4PAT/1Fsa9wfJo+yO5lUiQh3AAe8vZ82NR8U2EGB9I= 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 1601624629306322.74986089359265; Fri, 2 Oct 2020 00:43:49 -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-588-HXrBcLEJMHipYuEd50XtRA-1; Fri, 02 Oct 2020 03:43:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3736D801AFB; Fri, 2 Oct 2020 07:43:40 +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 177D05D9E4; Fri, 2 Oct 2020 07:43:40 +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 D6D4044A67; Fri, 2 Oct 2020 07:43:39 +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 0927hK3j004136 for ; Fri, 2 Oct 2020 03:43:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8047119931; Fri, 2 Oct 2020 07:43:20 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id D19F11992F for ; Fri, 2 Oct 2020 07:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624627; 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=szv4glwUfHBXZl6FhBS+Ch6qPH8kS0h+OBwgJ/dMxD0=; b=YCbXfOL93bwjF4kCBiCTNxe5RclfI70h5zO3lVKUVDposxa7h/xDYmnsTBCmNLQnhP2S6a sMBcu6/i2Bke2apS/yUn4TScxcA2u+YfOjE38G8gIf6oP0J45+ShVALOSlY3oq+WLLIxsA okTlZLT7It0lu87XX5St1zTrBm99U24= X-MC-Unique: HXrBcLEJMHipYuEd50XtRA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/15] virbitmaptest: test13: Refactor memory cleanup Date: Fri, 2 Oct 2020 09:42:59 +0200 Message-Id: <6e288d0c45dc98388ed7a158094f604a0ff9d653.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.14 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" Move scope of variables and get rid of the 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbitmaptest.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index e1a49bfe35..1578cd0612 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -670,37 +670,27 @@ test12(const void *opaque G_GNUC_UNUSED) static int test13(const void *opaque G_GNUC_UNUSED) { - virBitmapPtr map =3D NULL; const char *strings[] =3D { "1234feebee", "000c0fefe" }; - char *str =3D NULL; size_t i =3D 0; - int ret =3D -1; for (i =3D 0; i < G_N_ELEMENTS(strings); i++) { - map =3D virBitmapNewString(strings[i]); - if (!map) - goto cleanup; + g_autoptr(virBitmap) map =3D NULL; + g_autofree char *str =3D NULL; - str =3D virBitmapToString(map); - if (!str) - goto cleanup; + if (!(map =3D virBitmapNewString(strings[i]))) + return -1; + + if (!(str =3D virBitmapToString(map))) + return -1; if (STRNEQ(strings[i], str)) { - fprintf(stderr, "\n expected bitmap string '%s' actual string " - "'%s'\n", strings[i], str); - goto cleanup; + fprintf(stderr, "\n expected bitmap string '%s' actual string = '%s'\n", + strings[i], str); + return -1; } - - VIR_FREE(str); - virBitmapFree(map); - map =3D NULL; } - ret =3D 0; - cleanup: - VIR_FREE(str); - virBitmapFree(map); - return ret; + return 0; } #undef TEST_MAP --=20 2.26.2 From nobody Mon Apr 29 21:56:55 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=1601624707; cv=none; d=zohomail.com; s=zohoarc; b=HS4a6VpPFUe/f7OSd5wNJYwpaWa6RggnOAfdR2UMZSX8DdARvzdHRS+oGuDE64Bf3wY+BQaLZusqjCnaQb63WPS6e3Tv1lv016Av4oKE6sarBvHaNfLTtqoVJH1cAKl0xbc5FnoOpCIVdcwR+xPfwo2qMM4wcwnKwJm9VyAmn1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624707; 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=Y7aKjrJL7mkcAF7mNVfKGJqT4rh5uFfwh1v2W3tRIKo=; b=bLcvhREhF9yPhKkn67MPk4xt/csuwS9NmQaygn7XnLc34KKJ6kEk0iVZJBJJtsXDl3SNQbeYkb5dpudfvO0VhRVYd/b4Rjo5macAN0/90/oQoVEwjKfGs10eMHP9NGEG3V0xJhA6rKZ5M0cwTIWO4PGB8JBSdV/E82ioobw8G0w= 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) header.from= 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 1601624707288178.59288633895642; Fri, 2 Oct 2020 00:45:07 -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-141-1hLXdw1hOISyvw3h-FSL_g-1; Fri, 02 Oct 2020 03:43:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4243F6408E; Fri, 2 Oct 2020 07:43:39 +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 220E35D9E4; Fri, 2 Oct 2020 07:43:39 +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 DE9C51826D2E; Fri, 2 Oct 2020 07:43:38 +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 0927hLsQ004153 for ; Fri, 2 Oct 2020 03:43:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E92019931; Fri, 2 Oct 2020 07:43:21 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF4211992F for ; Fri, 2 Oct 2020 07:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624706; 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=Y7aKjrJL7mkcAF7mNVfKGJqT4rh5uFfwh1v2W3tRIKo=; b=KlSv+Vn/Sb6A/CpkyiFmAQHlVrAJFSxVko9KhUpqpOY5MDZFyeqyzZrnKQrJXd7sJeksrW IYQZ2zGGQaw7WQJ9pKHIDC3cFFTdNZjraj9f61eQhSo6xXBikDNWuOn9YcqhOB5RfZo3Ce w+/Vv6fRHDEvoGjIm+cNBkCLT+4sVvs= X-MC-Unique: 1hLXdw1hOISyvw3h-FSL_g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/15] virbitmaptest: Use g_auto(free) for cleanup Date: Fri, 2 Oct 2020 09:43:00 +0200 Message-Id: <8b3faaece37dd6c13111187324c95c3295032e36.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.14 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 --- tests/virbitmaptest.c | 73 ++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 1578cd0612..bfca208a7f 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -29,7 +29,7 @@ static int test1(const void *data G_GNUC_UNUSED) { - virBitmapPtr bitmap; + g_autoptr(virBitmap) bitmap =3D NULL; int size; int bit; bool result; @@ -58,7 +58,6 @@ test1(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); return ret; } @@ -85,8 +84,8 @@ static int test2(const void *data G_GNUC_UNUSED) { const char *bitsString1 =3D "1-32,50,88-99,1021-1023"; - char *bitsString2 =3D NULL; - virBitmapPtr bitmap =3D NULL; + g_autofree char *bitsString2 =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; int ret =3D -1; int size =3D 1025; @@ -139,15 +138,13 @@ test2(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); - VIR_FREE(bitsString2); return ret; } static int test3(const void *data G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; int ret =3D -1; int size =3D 5; size_t i; @@ -167,7 +164,6 @@ test3(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); return ret; } @@ -185,7 +181,7 @@ test4(const void *data G_GNUC_UNUSED) 1, 5, 11, 13, 19, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }; - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; ssize_t i, j; if (G_N_ELEMENTS(bitsPos) + G_N_ELEMENTS(bitsPosInv) !=3D size) @@ -285,11 +281,9 @@ test4(const void *data G_GNUC_UNUSED) if (virBitmapNextClearBit(bitmap, -1) !=3D -1) goto error; - virBitmapFree(bitmap); return 0; error: - virBitmapFree(bitmap); return -1; } @@ -298,14 +292,14 @@ static int test5(const void *v G_GNUC_UNUSED) { char data[] =3D {0x01, 0x02, 0x00, 0x00, 0x04}; - unsigned char *data2 =3D NULL; + g_autofree unsigned char *data2 =3D NULL; int len2; int bits[] =3D {0, 9, 34}; - virBitmapPtr bitmap; + g_autoptr(virBitmap) bitmap =3D NULL; size_t i; ssize_t j; int ret =3D -1; - char *str =3D NULL; + g_autofree char *str =3D NULL; bitmap =3D virBitmapNewData(data, sizeof(data)); if (!bitmap) @@ -347,9 +341,6 @@ test5(const void *v G_GNUC_UNUSED) ret =3D 0; error: - VIR_FREE(str); - virBitmapFree(bitmap); - VIR_FREE(data2); return ret; } @@ -358,8 +349,8 @@ test5(const void *v G_GNUC_UNUSED) static int test6(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; - char *str =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; + g_autofree char *str =3D NULL; int size =3D 64; int ret =3D -1; @@ -432,15 +423,12 @@ test6(const void *v G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); - VIR_FREE(str); return ret; } static int test7(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap; size_t i; size_t maxBit[] =3D { 1, 8, 31, 32, 63, 64, 95, 96, 127, 128, 159, 160 @@ -448,7 +436,7 @@ test7(const void *v G_GNUC_UNUSED) size_t nmaxBit =3D 12; for (i =3D 0; i < nmaxBit; i++) { - bitmap =3D virBitmapNew(maxBit[i]); + g_autoptr(virBitmap) bitmap =3D virBitmapNew(maxBit[i]); if (!bitmap) goto error; @@ -466,21 +454,18 @@ test7(const void *v G_GNUC_UNUSED) virBitmapClearAll(bitmap); if (!virBitmapIsAllClear(bitmap)) goto error; - - virBitmapFree(bitmap); } return 0; error: - virBitmapFree(bitmap); return -1; } static int test8(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; char data[108] =3D {0x00,}; int ret =3D -1; @@ -499,7 +484,6 @@ test8(const void *v G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(bitmap); return ret; } @@ -509,7 +493,7 @@ static int test9(const void *opaque G_GNUC_UNUSED) { int ret =3D -1; - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; if (virBitmapParse("100000000", &bitmap, 20) !=3D -1) goto cleanup; @@ -531,7 +515,6 @@ test9(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(bitmap); return ret; } @@ -540,7 +523,10 @@ static int test10(const void *opaque G_GNUC_UNUSED) { int ret =3D -1; - virBitmapPtr b1 =3D NULL, b2 =3D NULL, b3 =3D NULL, b4 =3D NULL; + g_autoptr(virBitmap) b1 =3D NULL; + g_autoptr(virBitmap) b2 =3D NULL; + g_autoptr(virBitmap) b3 =3D NULL; + g_autoptr(virBitmap) b4 =3D NULL; if (virBitmapParseSeparator("0-3,5-8,11-15f16", 'f', &b1, 20) < 0 || virBitmapParse("4,9,10,16-19", &b2, 20) < 0 || @@ -561,10 +547,6 @@ test10(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(b1); - virBitmapFree(b2); - virBitmapFree(b3); - virBitmapFree(b4); return ret; } @@ -578,9 +560,9 @@ static int test11(const void *opaque) { const struct testBinaryOpData *data =3D opaque; - virBitmapPtr amap =3D NULL; - virBitmapPtr bmap =3D NULL; - virBitmapPtr resmap =3D NULL; + 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 || @@ -600,9 +582,6 @@ test11(const void *opaque) ret =3D 0; cleanup: - virBitmapFree(amap); - virBitmapFree(bmap); - virBitmapFree(resmap); return ret; } @@ -631,7 +610,7 @@ test11(const void *opaque) static int test12(const void *opaque G_GNUC_UNUSED) { - virBitmapPtr map =3D virBitmapNewEmpty(); + g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); int ret =3D -1; TEST_MAP(0, ""); @@ -661,7 +640,6 @@ test12(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(map); return ret; } @@ -699,9 +677,9 @@ static int test14(const void *opaque) { const struct testBinaryOpData *data =3D opaque; - virBitmapPtr amap =3D NULL; - virBitmapPtr bmap =3D NULL; - virBitmapPtr resmap =3D NULL; + 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 || @@ -721,9 +699,6 @@ test14(const void *opaque) ret =3D 0; cleanup: - virBitmapFree(amap); - virBitmapFree(bmap); - virBitmapFree(resmap); return ret; } --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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 From nobody Mon Apr 29 21:56:55 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=1601624632; cv=none; d=zohomail.com; s=zohoarc; b=NsmH6w02lmcWIK4L3NNeJMwz4M29mXQm/4kCJSlzQb9/Yc65rR3GajH2rK8km7E2Sj7wsL60usjd5GlE8fXCuqbbRPx2BsyJaDHIb/M+j2n3b5E7qp0lhnEtfojQA6yb33gcEiO7HoMa8pdp2PqzMTx6Bhgygmrk6CyufpLMm8s= 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=Q3aB6dqWXotKucMTe1xpCCCpxZTRD6slr/XxkTVfCRg=; b=DoEh8aJKXvE1taNtdG+B164zpZQY0cdD3To+ItfAEvaKlUhKMC7IM38tXAwVRMdpGGSyefcIebjSTpEZOp4thd5utappfrTBIQb5uclzGQ/Y7PIgrNYyC0qr8ZMV8cU05KA00654Tf5A1Y1vTexx/5+j1fv1lQIs3ZajeZlkquo= 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) header.from= 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 1601624632284988.2790423125473; 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-445-W_JQaKt8PqaES3YpdHPrzw-1; Fri, 02 Oct 2020 03:43:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03CB4101FFAE; 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 D42D25D9E4; Fri, 2 Oct 2020 07:43:41 +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 A0AB944A6A; Fri, 2 Oct 2020 07:43:41 +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 0927hNEI004181 for ; Fri, 2 Oct 2020 03:43:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id E84251972A; Fri, 2 Oct 2020 07:43:23 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E6BD1992F for ; Fri, 2 Oct 2020 07:43:23 +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=Q3aB6dqWXotKucMTe1xpCCCpxZTRD6slr/XxkTVfCRg=; b=JGDeu6HcO8YKjPM07z98bAG8KOeGxLpRPD14P0wU17jboOVFn+5B/EeMqSWcbvK/Ywi0da A70LH+V5vViZHauHe7YYwvCkOOmN6CnyK1zgP4aYwFgGedHnQFhxawVHCP/mHJLfZ3Vk4I gYFRYltnhWP4eCtL4vPdtSY+7Dx0jDM= X-MC-Unique: W_JQaKt8PqaES3YpdHPrzw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/15] util: virbitmap: Don't forbid 0 size bitmap Date: Fri, 2 Oct 2020 09:43:02 +0200 Message-Id: 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.14 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" We now have APIs which automatically expand the bitmap and also API which allocates a 0 size bitmap. Remove the condition from virBitmapNew. Effectively reverts ce49cfb48ad Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index f1443c3ecf..5df7ea7838 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -55,8 +55,8 @@ struct _virBitmap { * * Allocate a bitmap capable of containing @size bits. * - * Returns a pointer to the allocated bitmap or NULL if either memory cann= ot be - * allocated or size is 0. Does not report libvirt errors. + * Returns a pointer to the allocated bitmap or NULL if memory cannot be + * allocated. Does not report libvirt errors. */ virBitmapPtr virBitmapNewQuiet(size_t size) @@ -64,12 +64,16 @@ virBitmapNewQuiet(size_t size) virBitmapPtr bitmap; size_t sz; - if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size || size =3D=3D 0) + if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size) return NULL; sz =3D VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT); bitmap =3D g_new0(virBitmap, 1); + + if (size =3D=3D 0) + return bitmap; + bitmap->map =3D g_new0(unsigned long, sz); bitmap->nbits =3D size; bitmap->map_len =3D sz; --=20 2.26.2 From nobody Mon Apr 29 21:56:55 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=1601624625; cv=none; d=zohomail.com; s=zohoarc; b=Ki15B+B2ozvjDCQvHzqqjj2TWYSAiPFG3MqMdrQCfRBkUakGLZdK43tDrQ0bu22C3/1G3/MNtzDBhQtTGhoxuqs2QZdcEAf4fO3QGSqOdOp0Brt9jgOPjejO84/52ThmhUcd+tpT10K+BZBTWuneYHD/xnz9VQIRQAZXHDbmyHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624625; 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=zu4tHG3FeYiFxY5yiGkVtlpHhETZDFz3bxaIg3jLdFw=; b=MC8l88DjSTOlDUQDU53C2oahZkAFwmzmzZsOlhw76Civ4cgUU9qPkF6jIvQ9FNB0h1NE4bumEoMOwkq4RiwcG+1NuhRY3KDyQH6hz2UGT08kwKn1gtBGsRYJiSzpZsV/P/Nswv325bDmPz5chb1K3PB8/y4Yg6O7yCCXLj5U/NU= 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) header.from= 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 1601624625181744.1394090927483; Fri, 2 Oct 2020 00:43:45 -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-225-VKgNYskBOR6CvAR7_qtVVw-1; Fri, 02 Oct 2020 03:43:42 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AF6C803F57; Fri, 2 Oct 2020 07:43:36 +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 5B1F35578C; Fri, 2 Oct 2020 07:43:36 +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 F24F744A65; Fri, 2 Oct 2020 07:43:35 +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 0927hPQp004188 for ; Fri, 2 Oct 2020 03:43:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 07BC01972A; Fri, 2 Oct 2020 07:43:25 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59FFD1992F for ; Fri, 2 Oct 2020 07:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624624; 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=zu4tHG3FeYiFxY5yiGkVtlpHhETZDFz3bxaIg3jLdFw=; b=Dan5xvU54DOVZFxbIvrjRYeXqPTzEcLz2bb2IdmXetY9zm/qaVUidC171YKVUVxozH0q3H /cxJZfe2/he/dbKiUzxjgQsU8bkx4mv16jiz2rWi8b/fwqLlfi+a+OjmpddK/n7sbDgLWd yTvRlztJNTLqZj4vbWoNNEoh4hFHb3U= X-MC-Unique: VKgNYskBOR6CvAR7_qtVVw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/15] virbitmaptest: Add few more cases for virBitmapToString Date: Fri, 2 Oct 2020 09:43:03 +0200 Message-Id: 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.15 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" Test an empty bitmap including it's extension via the self-expanding APIs and and a "0" and "" strings when converting the string back and forth. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbitmaptest.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 56110971c9..c14a6c7e26 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -605,7 +605,7 @@ test12(const void *opaque G_GNUC_UNUSED) static int test13(const void *opaque G_GNUC_UNUSED) { - const char *strings[] =3D { "1234feebee", "000c0fefe" }; + const char *strings[] =3D { "1234feebee", "000c0fefe", "0", "" }; size_t i =3D 0; for (i =3D 0; i < G_N_ELEMENTS(strings); i++) { @@ -684,6 +684,36 @@ test15(const void *opaque) } +/* virBitmapNewEmpty + virBitmapToString */ +static int +test16(const void *opaque G_GNUC_UNUSED) +{ + g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); + g_autofree char *res_empty =3D NULL; + g_autofree char *res_set =3D NULL; + + if (!(res_empty =3D virBitmapToString(map)) || + STRNEQ_NULLABLE(res_empty, "")) { + fprintf(stderr, "\n expected bitmap string '%s' actual string '%s'= \n", + "", NULLSTR(res_empty)); + return -1; + } + + if (virBitmapSetBitExpand(map, 2) < 0 || + virBitmapSetBitExpand(map, 11) < 0) + abort(); + + if (!(res_set =3D virBitmapToString(map)) || + STRNEQ_NULLABLE(res_set, "804")) { + fprintf(stderr, "\n expected bitmap string '%s' actual string '%s'= \n", + "804", NULLSTR(res_set)); + return -1; + } + + return 0; +} + + #define TESTBINARYOP(A, B, RES, FUNC) \ testBinaryOpData.a =3D A; \ testBinaryOpData.b =3D B; \ @@ -751,6 +781,9 @@ mymain(void) TESTBINARYOP("12345", "0,^0", "12345", test15); TESTBINARYOP("0,^0", "0,^0", "0,^0", test15); + if (virTestRun("test16", test16, NULL) < 0) + ret =3D -1; + return ret; } --=20 2.26.2 From nobody Mon Apr 29 21:56:55 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=1601624634; cv=none; d=zohomail.com; s=zohoarc; b=EJCMTgLJV1PGIU3Zvztth3AbWUf8l4B8MuZI0tIqXTXnJYMXvpD+b/98Ze5PuD1qBo+4y3oMiLbvUAptbTYqOlx+sS28PGkn6x/rmcS6GLb2L2Ryq2I3qJFExCRHI36361dn8bDgp5Ea1OFuRM1ZAiNvh+v2cjntFY1d32Z3Emc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624634; 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=rCAHCsEewI9EmM8cAub2Vv1kwos7YKoBZRQX0WevMt4=; b=HitfOpQywQKp6FBZhf8pVZbjupf6LpvWgoUn8BXsbdg/cyure9Ae6Mdf+rxIZzTz+f6ttzOzb40gOIocq+SAkNdyov7lO374qJNfEqtQgzXp34pBM/IPcp+t1OSEya5YGMvMehLjTT6VYcdLTeowLm4PpLlExaj9xoEdNcF7Dpo= 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) header.from= 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 1601624634587910.5390508939303; Fri, 2 Oct 2020 00:43:54 -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-505-AWvpfYazMv2yvm26CYDnWw-1; Fri, 02 Oct 2020 03:43:51 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B663101FFB4; Fri, 2 Oct 2020 07:43:44 +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 592CE5C1D0; Fri, 2 Oct 2020 07:43:44 +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 22119181A050; Fri, 2 Oct 2020 07:43:44 +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 0927hQFj004206 for ; Fri, 2 Oct 2020 03:43:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21C61196FE; Fri, 2 Oct 2020 07:43:26 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B5E41972A for ; Fri, 2 Oct 2020 07:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624633; 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=rCAHCsEewI9EmM8cAub2Vv1kwos7YKoBZRQX0WevMt4=; b=UwOrmIcdXvbv9/BOFD6TpjeN7Vr14hmfi7xXkP2eY4cBGpwBPVFuBYqVS1/URVxqXHpKWP tNC9g+eVN+UBjmpMFsfRWf2Avqkqa2nmYxHuZmNrCg0REYtfbeLmlfRX3InEMOe0vAmcKl pVSuCGW0b6NNkB+OA9aHjw2biehq3rU= X-MC-Unique: AWvpfYazMv2yvm26CYDnWw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/15] virBitmapNewQuiet: Don't fail on unlikely overflow scenario Date: Fri, 2 Oct 2020 09:43:04 +0200 Message-Id: <566c5e15b037d438a7b6d07312e53c46a3e307bc.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.16 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" Modify the condition which would make virBitmapNewQuiet fail to possibly overallocate by 1 rather than failing. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 5df7ea7838..a49019f884 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -55,8 +55,7 @@ struct _virBitmap { * * Allocate a bitmap capable of containing @size bits. * - * Returns a pointer to the allocated bitmap or NULL if memory cannot be - * allocated. Does not report libvirt errors. + * Returns a pointer to the allocated bitmap. */ virBitmapPtr virBitmapNewQuiet(size_t size) @@ -64,10 +63,13 @@ virBitmapNewQuiet(size_t size) virBitmapPtr bitmap; size_t sz; - if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size) - return NULL; - - sz =3D VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT); + if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size) { + /* VIR_DIV_UP would overflow, let's overallocate by 1 entry instea= d of + * the potential overflow */ + sz =3D (size / VIR_BITMAP_BITS_PER_UNIT) + 1; + } else { + sz =3D VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT); + } bitmap =3D g_new0(virBitmap, 1); --=20 2.26.2 From nobody Mon Apr 29 21:56:55 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=1601624629; cv=none; d=zohomail.com; s=zohoarc; b=ROhSSIVLMgkAkUaL9fX2BY4H90zfrGgW5GehQ6HuSCA66ST0Iu/kMKs9rq8IOHnYCufVZS1wkXESauUAZarS+kMGEAumwTym8LCQVBqzDEI7qqYgtPkinMQ/KUkSo0cIh3nzAVPzDmDqrNCH/HSeOgp/8CiOwHdhfY5LoV4kMSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624628; 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=kcilsRZ+/aXouqcBzG4CIjN7yyhuFrRmVz7dzVISEeg=; b=nBXOaj+r+4tQp6h7A3BdI/KIQsu60UD4M/kP9Q+h0j3iBtHj0yIDV8z6/gdfenci5Nj0OxiY5goOSJ5TiWUIY4gOYqFJZ+rgQWNe+PSPklqNeROz6av5ZUGsu+480ZPDRXQiNt1M/H8pQVV49AaUTF5RyK1Sbrwl5loiLhUXxgM= 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) header.from= 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 160162462899258.19128023291785; Fri, 2 Oct 2020 00:43:48 -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-345-dzQYF7zUPuyugfXFNkSZAQ-1; Fri, 02 Oct 2020 03:43:44 -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 EBF96803F5D; Fri, 2 Oct 2020 07:43:38 +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 CB43873685; Fri, 2 Oct 2020 07:43:38 +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 9A97444A66; Fri, 2 Oct 2020 07:43:38 +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 0927hRe6004219 for ; Fri, 2 Oct 2020 03:43:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27A821972A; Fri, 2 Oct 2020 07:43:27 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ACC719648 for ; Fri, 2 Oct 2020 07:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624626; 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=kcilsRZ+/aXouqcBzG4CIjN7yyhuFrRmVz7dzVISEeg=; b=OOXXmNxmxEDr+nXH0VYHUbFhIDWMk6gsahyNO0u8KhTrlUSCDaQT4045+gt9ujNh2aQfir VXW9FjenPpPAUfDwP0G+OJCVuzAa7NPQ3HkSe9I8A8lJ27iGej+qnWwBgZy70tYgd3qyUd N0+rAos9U+BCLR1X9B0ZuABzZAbTAIA= X-MC-Unique: dzQYF7zUPuyugfXFNkSZAQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/15] util: bitmap: Remove virBitmapNewQuiet Date: Fri, 2 Oct 2020 09:43:05 +0200 Message-Id: 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" We no longer report any errors so all callers can be replaced by virBitmapNew. Additionally virBitmapNEw can't return NULL now so error handling is not necessary. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virbitmap.c | 25 ++----------------------- src/util/virbitmap.h | 1 - src/util/virjson.c | 3 +-- tools/virt-host-validate-common.c | 4 +--- 5 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4e66385bab..185f120f6b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1684,7 +1684,6 @@ virBitmapNew; virBitmapNewCopy; virBitmapNewData; virBitmapNewEmpty; -virBitmapNewQuiet; virBitmapNewString; virBitmapNextClearBit; virBitmapNextSetBit; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index a49019f884..5d224a8def 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -50,7 +50,7 @@ struct _virBitmap { /** - * virBitmapNewQuiet: + * virBitmapNew: * @size: number of bits * * Allocate a bitmap capable of containing @size bits. @@ -58,7 +58,7 @@ struct _virBitmap { * Returns a pointer to the allocated bitmap. */ virBitmapPtr -virBitmapNewQuiet(size_t size) +virBitmapNew(size_t size) { virBitmapPtr bitmap; size_t sz; @@ -84,27 +84,6 @@ virBitmapNewQuiet(size_t size) } -/** - * virBitmapNew: - * @size: number of bits - * - * Allocate a bitmap capable of containing @size bits. - * - * Returns a pointer to the allocated bitmap or NULL if either memory cann= ot be - * allocated or size is 0. Reports libvirt errors. - */ -virBitmapPtr -virBitmapNew(size_t size) -{ - virBitmapPtr ret; - - if (!(ret =3D virBitmapNewQuiet(size))) - virReportOOMError(); - - return ret; -} - - /** * virBitmapNewEmpty: * diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 615ec6e4af..57264fef0e 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -32,7 +32,6 @@ typedef virBitmap *virBitmapPtr; /* * Allocate a bitmap capable of containing @size bits. */ -virBitmapPtr virBitmapNewQuiet(size_t size) G_GNUC_WARN_UNUSED_RESULT; virBitmapPtr virBitmapNew(size_t size) G_GNUC_WARN_UNUSED_RESULT; virBitmapPtr virBitmapNewEmpty(void) G_GNUC_WARN_UNUSED_RESULT; diff --git a/src/util/virjson.c b/src/util/virjson.c index ba43d6b667..a4fc9e990e 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1257,8 +1257,7 @@ virJSONValueGetArrayAsBitmap(const virJSONValue *val, maxelem =3D elems[i]; } - if (!(*bitmap =3D virBitmapNewQuiet(maxelem + 1))) - return -1; + *bitmap =3D virBitmapNew(maxelem + 1); /* second pass sets the correct bits in the map */ for (i =3D 0; i < val->data.array.nvalues; i++) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index e0e22a133a..c3784bb91d 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -196,8 +196,7 @@ virBitmapPtr virHostValidateGetCPUFlags(void) if (!(fp =3D fopen("/proc/cpuinfo", "r"))) return NULL; - if (!(flags =3D virBitmapNewQuiet(VIR_HOST_VALIDATE_CPU_FLAG_LAST))) - goto cleanup; + flags =3D virBitmapNew(VIR_HOST_VALIDATE_CPU_FLAG_LAST); do { char line[1024]; @@ -245,7 +244,6 @@ virBitmapPtr virHostValidateGetCPUFlags(void) virStringListFreeCount(tokens, ntokens); } while (1); - cleanup: VIR_FORCE_FCLOSE(fp); return flags; --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624633; cv=none; d=zohomail.com; s=zohoarc; b=fJj0DGvIhRVDDVLckZGf4v57JyMhJsHy9J+ET+2ffYTx75ehq5ZqfFvDatBq/CvzwJum8zKYoOFHayouJfC11x6dcTuzMihzcLtsUfLD04A2avlfvGhmV2WUn2G20EqgEb4ZTELquZ9RFaRgZe5kNxsKDkk2/6lFA8CpQHDSl7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624633; 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=+5o4VSK5wMLGCtF9VrIk+9uIVTj0/e9SWbUlYlbHW2U=; b=Fid+v2movf07HKC/MczYzEZlAOAnDI9Thn20pFI8hFu3GC/q3OjRKr+kK+sGVsCZQcMVJKGh7xLEjBjpbQsZi6kCsP5ejmuPV+kl32qhVTGv3cz82mna21p+YtHuBZY5c+w/q7ErbXmxYV9Mx1Q3VJBu5GOK6i1Teq8NbLn89TY= 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 1601624633153636.0148988938768; Fri, 2 Oct 2020 00:43:53 -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-420-kCCtz5-1NoSOCi69m2cwNg-1; Fri, 02 Oct 2020 03:43:50 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFCFE801AE2; Fri, 2 Oct 2020 07:43:41 +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 8CFEA5C1DA; Fri, 2 Oct 2020 07:43:41 +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 561921800B72; Fri, 2 Oct 2020 07:43:41 +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 0927hSDI004239 for ; Fri, 2 Oct 2020 03:43:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 390C11992F; Fri, 2 Oct 2020 07:43:28 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C26819931 for ; Fri, 2 Oct 2020 07:43:27 +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=+5o4VSK5wMLGCtF9VrIk+9uIVTj0/e9SWbUlYlbHW2U=; b=awdW1GG4L01rfcMES3Pdu3oI8hZTirgkRySkflytEPAI3TCey5r0ePWkIXMuAQ2+llkb28 XRv2vYUTJgPaEQKe338fqSDwAvncIgbjVcP7yhbTW2TpQDNeu++oQKwu3KXcORieyu0zxW S63L1/wXjUCU3Hwrz9pdhALYUabxuck= X-MC-Unique: kCCtz5-1NoSOCi69m2cwNg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/15] virBitmapNew: Don't force return value check Date: Fri, 2 Oct 2020 09:43:06 +0200 Message-Id: <8593457cbb38eedcdcf8b71b71d196d1acf74d1a.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.16 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" We now always return a valid pointer or crash so the return value doesn't need to be checked. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 57264fef0e..88af3bbadc 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -32,7 +32,7 @@ typedef virBitmap *virBitmapPtr; /* * Allocate a bitmap capable of containing @size bits. */ -virBitmapPtr virBitmapNew(size_t size) G_GNUC_WARN_UNUSED_RESULT; +virBitmapPtr virBitmapNew(size_t size); virBitmapPtr virBitmapNewEmpty(void) G_GNUC_WARN_UNUSED_RESULT; /* --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624710; cv=none; d=zohomail.com; s=zohoarc; b=Yhu/j/hZfa+waZcsOdrBi1AcSx6ALyHA6SLCgyK/x7BwwntB8z/0iHraYrsiwv0YN8lo6V7wZqAzrJtlWPDiTWRxe19mu4uyxRQUL5IvntqmuhvUpr0Y3UiazKHEMacPvVbN6s6748JluRFUQeTHe17QhGuPVQdjXRaMNcPTjf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624710; 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=V0mnIy2N280/RWWcqF3wCvLwkm6jRCqKkIIQsqiJWis=; b=LAI5SFGHHLi3lVq+szGUasc19aPLMG7aEW7DmYbaKQCy+Me48AZtCeLthVK8RrfTrAhcYisc7fZVNGQCkPJMdiSUnyfeejRuDcIIfQYnxiaAu85DT5kr0/39BsuvzML+41GprhopJZJUqNXF4USnAqf9roNgkzwsIdW3WMq2jCs= 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 1601624710420744.2460860195706; Fri, 2 Oct 2020 00:45:10 -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-253-r5BM7K7tNpWKoInZqz3AfQ-1; Fri, 02 Oct 2020 03:43:50 -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 334246408C; Fri, 2 Oct 2020 07:43:44 +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 105DF10016DA; Fri, 2 Oct 2020 07:43:44 +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 CFF7A18199F8; Fri, 2 Oct 2020 07:43:43 +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 0927hTRP004260 for ; Fri, 2 Oct 2020 03:43:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C0DE19931; Fri, 2 Oct 2020 07:43:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6BFA1992F for ; Fri, 2 Oct 2020 07:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624709; 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=V0mnIy2N280/RWWcqF3wCvLwkm6jRCqKkIIQsqiJWis=; b=iLPF8w8B4jlkFqfy0Y0wtMJhPbHkUBUuW6W9UCDLnCI8c4WirVOZ5f0kLFS+LCJJI6N3uU CDOj/+CFsoJZPY0d+EEp58KqxobW0Ckiu7b7aEI7XAnqhEu3L2Cgios/u8VJYnf6zhgp9E qzl1DW927WhQcwsJbivTBN98UpZymBM= X-MC-Unique: r5BM7K7tNpWKoInZqz3AfQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/15] util: bitmp: Remove virBitmapNewEmpty Date: Fri, 2 Oct 2020 09:43:07 +0200 Message-Id: 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.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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" It can be replaced by virBitmapNew(0). Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/numa_conf.c | 2 +- src/libvirt_private.syms | 1 - src/util/virbitmap.c | 16 +--------------- src/util/virbitmap.h | 1 - src/util/virhostcpu.c | 4 ++-- src/util/virnuma.c | 2 +- src/util/virtpm.c | 2 +- tests/virbitmaptest.c | 8 ++++---- 8 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index cc6c77f105..b5ddf2c134 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -1374,7 +1374,7 @@ virDomainNumaDefValidate(const virDomainNuma *def) for (i =3D 0; i < def->nmem_nodes; i++) { const virDomainNumaNode *node =3D &def->mem_nodes[i]; - g_autoptr(virBitmap) levelsSeen =3D virBitmapNewEmpty(); + g_autoptr(virBitmap) levelsSeen =3D virBitmapNew(0); for (j =3D 0; j < node->ncaches; j++) { const virDomainNumaCache *cache =3D &node->caches[j]; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 185f120f6b..01ae3cad93 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1683,7 +1683,6 @@ virBitmapLastSetBit; virBitmapNew; virBitmapNewCopy; virBitmapNewData; -virBitmapNewEmpty; virBitmapNewString; virBitmapNextClearBit; virBitmapNextSetBit; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 5d224a8def..1bff5d4ae6 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -84,20 +84,6 @@ virBitmapNew(size_t size) } -/** - * virBitmapNewEmpty: - * - * Allocate an empty bitmap. It can be used with self-expanding APIs. - * - * Returns a pointer to the allocated bitmap. - */ -virBitmapPtr -virBitmapNewEmpty(void) -{ - return g_new0(virBitmap, 1); -} - - /** * virBitmapFree: * @bitmap: previously allocated bitmap @@ -576,7 +562,7 @@ virBitmapParse(const char *str, virBitmapPtr virBitmapParseUnlimited(const char *str) { - virBitmapPtr bitmap =3D virBitmapNewEmpty(); + virBitmapPtr bitmap =3D virBitmapNew(0); bool neg =3D false; const char *cur =3D str; char *tmp; diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 88af3bbadc..cd5caa6f61 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -33,7 +33,6 @@ typedef virBitmap *virBitmapPtr; * Allocate a bitmap capable of containing @size bits. */ virBitmapPtr virBitmapNew(size_t size); -virBitmapPtr virBitmapNewEmpty(void) G_GNUC_WARN_UNUSED_RESULT; /* * Free previously allocated bitmap diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index f7e92cd924..c00a393def 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -336,7 +336,7 @@ virHostCPUParseNode(const char *node, goto cleanup; /* enumerate sockets in the node */ - sockets_map =3D virBitmapNewEmpty(); + sockets_map =3D virBitmapNew(0); while ((direrr =3D virDirRead(cpudir, &cpudirent, node)) > 0) { if (sscanf(cpudirent->d_name, "cpu%u", &cpu) !=3D 1) @@ -372,7 +372,7 @@ virHostCPUParseNode(const char *node, goto cleanup; for (i =3D 0; i < sock_max; i++) - cores_maps[i] =3D virBitmapNewEmpty(); + cores_maps[i] =3D virBitmapNew(0); /* Iterate over all CPUs in the node, in ascending order */ for (cpu =3D 0; cpu < npresent_cpus; cpu++) { diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 39f0f30917..5a1218cdf2 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -311,7 +311,7 @@ virNumaNodesetToCPUset(virBitmapPtr nodeset, if (!nodeset) return 0; - allNodesCPUs =3D virBitmapNewEmpty(); + allNodesCPUs =3D virBitmapNew(0); nodesetSize =3D virBitmapSize(nodeset); for (i =3D 0; i < nodesetSize; i++) { diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 1a3b5a05aa..0e11674a3c 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -183,7 +183,7 @@ virTPMExecGetCaps(virCommandPtr cmd, if (virCommandRun(cmd, &exitstatus) < 0) return NULL; - bitmap =3D virBitmapNewEmpty(); + bitmap =3D virBitmapNew(0); /* older version does not support --print-capabilties -- that's fine */ if (exitstatus !=3D 0) { diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index c14a6c7e26..255492c9e8 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -178,7 +178,7 @@ test4(const void *data G_GNUC_UNUSED) /* 0. empty set */ - bitmap =3D virBitmapNewEmpty(); + bitmap =3D virBitmapNew(0); if (virBitmapNextSetBit(bitmap, -1) !=3D -1) return -1; @@ -571,7 +571,7 @@ test11(const void *opaque) static int test12(const void *opaque G_GNUC_UNUSED) { - g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); + g_autoptr(virBitmap) map =3D virBitmapNew(0); TEST_MAP(0, ""); @@ -684,11 +684,11 @@ test15(const void *opaque) } -/* virBitmapNewEmpty + virBitmapToString */ +/* virBitmapNew(0) + virBitmapToString */ static int test16(const void *opaque G_GNUC_UNUSED) { - g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); + g_autoptr(virBitmap) map =3D virBitmapNew(0); g_autofree char *res_empty =3D NULL; g_autofree char *res_set =3D NULL; --=20 2.26.2 From nobody Mon Apr 29 21:56:55 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=1601624710; cv=none; d=zohomail.com; s=zohoarc; b=UmWc+qpbCTsu1JbmxJ/mpx8Q2WYWAmLDVdqN1RhSArdKJdlkQrtxrKy09IFQe+gQ4hVkYJAf3YBtshRCt18ndGCyNBOy/yVdvJNqTlYtQVI+uGbcP8nWC2r0aKRAMeW43+vNOy+JwDEx4FwH8BjdzncDRuQ1EMlkXpX32KPTTjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624710; 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=tVC1JoMLxjPaPOnbAD0ckwHjwLTfnROW2iIaPi0M3cw=; b=JjW11ChYs2ltsMcHc/qwrdfU5k1UnNZ5ykPR9upD0bGYk6ISyzcFZcI2cD04jKsT7cT5UEEsfQIpwX7wILfA3V8OKXgDHf/cgE4Q+aJXQBqtTHAUTB4jMVNFMnm6H4a6xhsy4lCksebtRiQ6nv4W8n/H2HLWRhtLgvTYidCsnqM= 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) header.from= 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 1601624710609824.9889417915857; Fri, 2 Oct 2020 00:45:10 -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-158-CUIYt2GBMGCnmoBcJ4PaJQ-1; Fri, 02 Oct 2020 03:43:52 -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 36531188C122; Fri, 2 Oct 2020 07:43:47 +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 AFB5019936; Fri, 2 Oct 2020 07:43:46 +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 7E9C044A5F; Fri, 2 Oct 2020 07:43:46 +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 0927hUgP004301 for ; Fri, 2 Oct 2020 03:43:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 63BF719931; Fri, 2 Oct 2020 07:43:30 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1DFB1992F for ; Fri, 2 Oct 2020 07:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624709; 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=tVC1JoMLxjPaPOnbAD0ckwHjwLTfnROW2iIaPi0M3cw=; b=VQLPjiHBBEMTAN8rBJm0k0N0Sksz5pjMNcJl68T0GZdkkeMtqqrM5bPDgM013y04mLWagi HJGW7DNTfJNQ1T/u1O3vZOlHbblBv7pGbtGcGEPNZKfJgKDiqhqFNen1XIINbdiMdXTYNu Ux/8b/XdRmls8g+gGCnw/ccegR5PkTI= X-MC-Unique: CUIYt2GBMGCnmoBcJ4PaJQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/15] qemuSlirpNew: Use g_new0 to allocate the slirp object Date: Fri, 2 Oct 2020 09:43:08 +0200 Message-Id: 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.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-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 --- src/qemu/qemu_slirp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index 3efc34bcf0..d9105b0ff6 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -81,10 +81,9 @@ qemuSlirpHasFeature(const qemuSlirp *slirp, qemuSlirpPtr qemuSlirpNew(void) { - g_autoptr(qemuSlirp) slirp =3D NULL; + g_autoptr(qemuSlirp) slirp =3D g_new0(qemuSlirp, 1); - if (VIR_ALLOC(slirp) < 0 || - !(slirp->features =3D virBitmapNew(QEMU_SLIRP_FEATURE_LAST))) + if (!(slirp->features =3D virBitmapNew(QEMU_SLIRP_FEATURE_LAST))) return NULL; slirp->pid =3D (pid_t)-1; --=20 2.26.2 From nobody Mon Apr 29 21:56:55 2024 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=1601624944; cv=none; d=zohomail.com; s=zohoarc; b=alrIJvvyz14vJzR1PFoIZeuxikIzoUuwB16zHzpDM4iPDaIWY5a6wKK2mYDWhzvsKwMq4ZkZIcORq/hiitGFKQcMtqOBKjS4N/y26ImA0LLtAQh3vQ8GZ68EmFYA8+DvgVdqAXLO0n8e/02P4XVfA1wgkLoeg6j+3jaeQEYdVGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624944; 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=WY8baP/5g30VkrwVlcWJW+a2aXz43C0U2lktAJbOShg=; b=fprDUxIL0e+72dcTgUE/ZJNriWWG843gOXPmZL4zLwuBTIlevjCSKxl+5QNBDzZ2VeCL8K4fq2KimLZ9LK5BAPEGK/6y9WkZTIdyXgn/oOqT3uiJ52oqh2J7pVBFsNt9IS8+UcU8wkWPbOgfG0e8AmSJGzDWOWKprI34tys2xUw= 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 1601624944144874.2699273746151; Fri, 2 Oct 2020 00:49:04 -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-50-aub1vL7PO-mU9k50mVLl8w-1; Fri, 02 Oct 2020 03:49:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 302808030B3; Fri, 2 Oct 2020 07:48:55 +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 9A7F35C1D0; Fri, 2 Oct 2020 07:48:54 +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 BDFE044A44; Fri, 2 Oct 2020 07:48:53 +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 0927hY9q004363 for ; Fri, 2 Oct 2020 03:43:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA3C71A8EC; Fri, 2 Oct 2020 07:43:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA5B81992F for ; Fri, 2 Oct 2020 07:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624942; 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=WY8baP/5g30VkrwVlcWJW+a2aXz43C0U2lktAJbOShg=; b=DcrSTnocvB7vD3O7sAA34h+7tHf87V2WgjTzC+cU9X9lyIBg9WKQikYAqIpEOsFT2ShmnO U5cpCoDBzhJTrU0snccUw9ahf8nYNoaZxDTiepzBJEZY7jXZ6/4RFCKz0VqoPlEfrEqk4E zkqBaeW59eYcx7H9aECm9dtgj9uRtUw= X-MC-Unique: aub1vL7PO-mU9k50mVLl8w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/15] virBitmapNew: Don't check return value Date: Fri, 2 Oct 2020 09:43:09 +0200 Message-Id: <52ea653f3a770ed5a450c7ab0068c507b5b0cb66.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.16 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" Remove return value check from all callers. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/capabilities.c | 7 ++----- src/conf/checkpoint_conf.c | 3 +-- src/conf/domain_addr.c | 6 ++---- src/conf/domain_conf.c | 12 ++++-------- src/conf/node_device_conf.c | 6 ++---- src/conf/storage_conf.c | 3 +-- src/conf/virnetworkobj.c | 3 +-- src/libxl/libxl_capabilities.c | 4 ---- src/libxl/libxl_driver.c | 6 ++---- src/lxc/lxc_controller.c | 3 --- src/qemu/qemu_capabilities.c | 3 +-- src/qemu/qemu_conf.c | 3 +-- src/qemu/qemu_domain_address.c | 5 +---- src/qemu/qemu_driver.c | 11 +++-------- src/qemu/qemu_hotplug.c | 3 +-- src/qemu/qemu_migration_cookie.c | 5 ++--- src/qemu/qemu_migration_params.c | 12 ++---------- src/qemu/qemu_monitor.c | 3 +-- src/qemu/qemu_namespace.c | 5 ++--- src/qemu/qemu_process.c | 5 +---- src/qemu/qemu_slirp.c | 4 +--- src/qemu/qemu_snapshot.c | 3 +-- src/test/test_driver.c | 12 +++--------- src/util/virbitmap.c | 12 ++---------- src/util/vircommand.c | 3 +-- src/util/virdnsmasq.c | 7 +------ src/util/virhostcpu.c | 10 +++------- src/util/virnetdev.c | 3 +-- src/util/virnuma.c | 6 ++---- src/util/virportallocator.c | 6 +----- src/util/virprocess.c | 6 ++---- src/util/virresctrl.c | 10 +--------- src/util/virstoragefile.c | 3 +-- src/vmx/vmx.c | 2 -- src/vz/vz_sdk.c | 3 +-- tests/qemumonitorjsontest.c | 3 --- tests/testutils.c | 11 ++--------- tests/virbitmaptest.c | 12 ++---------- tools/virsh-domain.c | 9 +++------ 39 files changed, 58 insertions(+), 175 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 610e6e8242..4a85c63628 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1411,9 +1411,7 @@ virCapabilitiesHostNUMAGetCpus(virCapsHostNUMAPtr cap= s, unsigned int maxcpu =3D virCapabilitiesHostNUMAGetMaxcpu(caps); ssize_t node =3D -1; - if (!(ret =3D virBitmapNew(maxcpu + 1))) - return NULL; - + ret =3D virBitmapNew(maxcpu + 1); while ((node =3D virBitmapNextSetBit(nodemask, node)) >=3D 0) { if (virCapabilitiesHostNUMAGetCellCpus(caps, node, ret) < 0) { @@ -1591,8 +1589,7 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMAPtr ca= ps) cpus[cid].die_id =3D 0; cpus[cid].socket_id =3D s; cpus[cid].core_id =3D c; - if (!(cpus[cid].siblings =3D virBitmapNew(ncpus))) - goto error; + cpus[cid].siblings =3D virBitmapNew(ncpus); virBitmapCopy(cpus[cid].siblings, siblings); cid++; } diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 914af4305d..f97621dabf 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -323,8 +323,7 @@ virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr= def) if (!def->ndisks) checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; - if (!(map =3D virBitmapNew(def->parent.dom->ndisks))) - goto cleanup; + map =3D virBitmapNew(def->parent.dom->ndisks); /* Double check requested disks. */ for (i =3D 0; i < def->ndisks; i++) { diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 6e77a72f7c..9114f2d8d0 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1595,8 +1595,7 @@ virDomainVirtioSerialAddrSetAddController(virDomainVi= rtioSerialAddrSetPtr addrs, if (VIR_ALLOC(cnt) < 0) goto cleanup; - if (!(cnt->ports =3D virBitmapNew(ports))) - goto cleanup; + cnt->ports =3D virBitmapNew(ports); cnt->idx =3D cont->idx; if ((insertAt =3D virDomainVirtioSerialAddrPlaceController(addrs, cnt)= ) < -1) @@ -2043,8 +2042,7 @@ virDomainUSBAddressHubNew(size_t nports) if (VIR_ALLOC(hub) < 0) goto cleanup; - if (!(hub->portmap =3D virBitmapNew(nports))) - goto cleanup; + hub->portmap =3D virBitmapNew(nports); if (VIR_ALLOC_N(hub->ports, nports) < 0) goto cleanup; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b80d7c7c6c..2fbfd949fd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2032,12 +2032,9 @@ virDomainDefGetVcpus(const virDomainDef *def) virBitmapPtr virDomainDefGetOnlineVcpumap(const virDomainDef *def) { - virBitmapPtr ret =3D NULL; + virBitmapPtr ret =3D virBitmapNew(def->maxvcpus); size_t i; - if (!(ret =3D virBitmapNew(def->maxvcpus))) - return NULL; - for (i =3D 0; i < def->maxvcpus; i++) { if (def->vcpus[i]->online) ignore_value(virBitmapSetBit(ret, i)); @@ -3311,8 +3308,7 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, return 0; /* iothread's are numbered starting at 1, account for that */ - if (!(thrmap =3D virBitmapNew(iothreads + 1))) - return -1; + thrmap =3D virBitmapNew(iothreads + 1); virBitmapSetAll(thrmap); /* Clear 0 since we don't use it, then mark those which are @@ -4505,8 +4501,8 @@ virDomainDefRejectDuplicateControllers(virDomainDefPt= r def) max_idx[VIR_DOMAIN_CONTROLLER_TYPE_USB] =3D -1; for (i =3D 0; i < VIR_DOMAIN_CONTROLLER_TYPE_LAST; i++) { - if (max_idx[i] >=3D 0 && !(bitmaps[i] =3D virBitmapNew(max_idx[i] = + 1))) - goto cleanup; + if (max_idx[i] >=3D 0) + bitmaps[i] =3D virBitmapNew(max_idx[i] + 1); nbitmaps++; } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index a9a03ad6c2..e478238675 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1143,10 +1143,8 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) < 0) goto out; - if (n > 0) { - if (!(net->features =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST))) - goto out; - } + if (n > 0) + net->features =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST); for (i =3D 0; i < n; i++) { int val; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index d53d50479b..ae63cc725e 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1444,8 +1444,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, if (!def->target.compat) def->target.compat =3D g_strdup("1.1"); - if (!(def->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATU= RE_LAST))) - return NULL; + def->target.features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAS= T); for (i =3D 0; i < n; i++) { int f =3D virStorageFileFeatureTypeFromString((const char*)nod= es[i]->name); diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 8b12ce0482..aefe23fde1 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -110,8 +110,7 @@ virNetworkObjNew(void) if (!(obj =3D virObjectLockableNew(virNetworkObjClass))) return NULL; - if (!(obj->classIdMap =3D virBitmapNew(INIT_CLASS_ID_BITMAP_SIZE))) - goto error; + obj->classIdMap =3D virBitmapNew(INIT_CLASS_ID_BITMAP_SIZE); /* The first three class IDs are already taken */ if (virBitmapSetBitExpand(obj->classIdMap, 0) < 0 || diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e3472acb4b..622cba1bfc 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -296,10 +296,6 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) cpus[node][nr_cpus_node[node]-1].core_id =3D cpu_topo[i].core; /* Allocate the siblings maps. We will be filling them later */ cpus[node][nr_cpus_node[node]-1].siblings =3D virBitmapNew(nr_cpus= ); - if (!cpus[node][nr_cpus_node[node]-1].siblings) { - virReportOOMError(); - goto cleanup; - } } /* Let's now populate the siblings bitmaps */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 80ee3ac5d0..446449fb33 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2571,8 +2571,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpum= aps, /* Make sure coverity knows targetDef is valid at this point. */ sa_assert(targetDef); - if (!(hostcpus =3D virBitmapNew(libxl_get_max_cpus(cfg->ctx)))) - goto cleanup; + hostcpus =3D virBitmapNew(libxl_get_max_cpus(cfg->ctx)); virBitmapSetAll(hostcpus); ret =3D virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, = cpumaps, @@ -4952,8 +4951,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom, virReportOOMError(); goto cleanup; } - if (!(nodes =3D virBitmapNew(numnodes))) - goto cleanup; + nodes =3D virBitmapNew(numnodes); rc =3D libxl_domain_get_nodeaffinity(cfg->ctx, vm->def->id, diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index c3cf485e2c..f70731bc64 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -756,9 +756,6 @@ static int virLXCControllerSetupCpuAffinity(virLXCContr= ollerPtr ctrl) maxcpu =3D hostcpus; cpumap =3D virBitmapNew(maxcpu); - if (!cpumap) - return -1; - cpumapToSet =3D cpumap; if (ctrl->def->cpumask) { diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ea2e4c0948..e3a934363b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1800,8 +1800,7 @@ virQEMUCapsNew(void) return NULL; qemuCaps->invalidation =3D true; - if (!(qemuCaps->flags =3D virBitmapNew(QEMU_CAPS_LAST))) - goto error; + qemuCaps->flags =3D virBitmapNew(QEMU_CAPS_LAST); if (!(qemuCaps->domCapsCache =3D virQEMUDomainCapsCacheNew())) goto error; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f4ed1fa061..2f5809e1ad 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -278,8 +278,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged, cfg->glusterDebugLevel =3D 4; cfg->stdioLogD =3D true; - if (!(cfg->namespaces =3D virBitmapNew(QEMU_DOMAIN_NS_LAST))) - return NULL; + cfg->namespaces =3D virBitmapNew(QEMU_DOMAIN_NS_LAST); if (privileged && qemuDomainNamespaceAvailable(QEMU_DOMAIN_NS_MOUNT) && diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 61eb53ea2c..a2b19da5ea 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -3056,13 +3056,10 @@ qemuDomainUSBAddressAddHubs(virDomainDefPtr def) static virBitmapPtr qemuDomainGetMemorySlotMap(const virDomainDef *def) { - virBitmapPtr ret; + virBitmapPtr ret =3D virBitmapNew(def->mem.memory_slots); virDomainMemoryDefPtr mem; size_t i; - if (!(ret =3D virBitmapNew(def->mem.memory_slots))) - return NULL; - for (i =3D 0; i < def->nmems; i++) { mem =3D def->mems[i]; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 85b6a6a321..c23dca9970 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19280,18 +19280,13 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPt= r *params, virTypedParameterPtr par =3D NULL; int npar =3D 0; int maxpar =3D 0; - virBitmapPtr vcpus =3D NULL; - virBitmapPtr online =3D NULL; - virBitmapPtr offlinable =3D NULL; + virBitmapPtr vcpus =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID); + virBitmapPtr online =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID); + virBitmapPtr offlinable =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID); g_autofree char *tmp =3D NULL; size_t i; int ret =3D -1; - if (!(vcpus =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID)) || - !(online =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID)) || - !(offlinable =3D virBitmapNew(QEMU_GUEST_VCPU_MAX_ID))) - goto cleanup; - for (i =3D 0; i < ninfo; i++) { if (virBitmapSetBit(vcpus, info[i].id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 11b549b12b..86ccb9bac4 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6150,8 +6150,7 @@ qemuDomainSelectHotplugVcpuEntities(virDomainDefPtr d= ef, unsigned int curvcpus =3D virDomainDefGetVcpus(def); ssize_t i; - if (!(ret =3D virBitmapNew(maxvcpus))) - return NULL; + ret =3D virBitmapNew(maxvcpus); if (nvcpus > curvcpus) { *enable =3D true; diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index c128f541dd..4b73a98f7e 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -1122,9 +1122,8 @@ qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ct= xt) if (VIR_ALLOC(caps) < 0) return NULL; - if (!(caps->supported =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST)) || - !(caps->automatic =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST))) - goto cleanup; + caps->supported =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); + caps->automatic =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); if ((n =3D virXPathNodeSet("./capabilities[1]/cap", ctxt, &nodes)) < 0) goto cleanup; diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index 5fde915963..df5560d39f 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -224,12 +224,9 @@ G_STATIC_ASSERT(G_N_ELEMENTS(qemuMigrationParamTypes) = =3D=3D QEMU_MIGRATION_PARAM_LA virBitmapPtr qemuMigrationParamsGetAlwaysOnCaps(qemuMigrationParty party) { - virBitmapPtr caps =3D NULL; + virBitmapPtr caps =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); size_t i; - if (!(caps =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST))) - return NULL; - for (i =3D 0; i < G_N_ELEMENTS(qemuMigrationParamsAlwaysOn); i++) { if (!(qemuMigrationParamsAlwaysOn[i].party & party)) continue; @@ -248,8 +245,7 @@ qemuMigrationParamsNew(void) params =3D g_new0(qemuMigrationParams, 1); - if (!(params->caps =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST))) - return NULL; + params->caps =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); return g_steal_pointer(¶ms); } @@ -1373,8 +1369,6 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver, return 0; priv->migrationCaps =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); - if (!priv->migrationCaps) - return -1; for (capStr =3D caps; *capStr; capStr++) { int cap =3D qemuMigrationCapabilityTypeFromString(*capStr); @@ -1389,8 +1383,6 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver, if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT)) { migEvent =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); - if (!migEvent) - return -1; ignore_value(virBitmapSetBit(migEvent, QEMU_MIGRATION_CAP_EVENTS)); diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index eb4b04dc1a..c6be72dabc 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1937,8 +1937,7 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon, if (rc < 0) goto cleanup; - if (!(ret =3D virBitmapNew(maxvcpus))) - goto cleanup; + ret =3D virBitmapNew(maxvcpus); for (i =3D 0; i < ncpuentries; i++) { if (cpuentries[i].halted) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index b0d1d0d083..ec52fe7ea5 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -799,9 +799,8 @@ qemuDomainEnableNamespace(virDomainObjPtr vm, { qemuDomainObjPrivatePtr priv =3D vm->privateData; - if (!priv->namespaces && - !(priv->namespaces =3D virBitmapNew(QEMU_DOMAIN_NS_LAST))) - return -1; + if (!priv->namespaces) + priv->namespaces =3D virBitmapNew(QEMU_DOMAIN_NS_LAST); if (virBitmapSetBit(priv->namespaces, ns) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9122069cc9..8814e61314 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5870,12 +5870,9 @@ qemuProcessValidateHotpluggableVcpus(virDomainDefPtr= def) unsigned int maxvcpus =3D virDomainDefGetVcpusMax(def); size_t i =3D 0; size_t j; - virBitmapPtr ordermap =3D NULL; + virBitmapPtr ordermap =3D virBitmapNew(maxvcpus + 1); int ret =3D -1; - if (!(ordermap =3D virBitmapNew(maxvcpus + 1))) - goto cleanup; - /* validate: * - all hotpluggable entities to be hotplugged have the correct data * - vcpus belonging to a hotpluggable entity share configuration diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index d9105b0ff6..d2e4ed79be 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -83,9 +83,7 @@ qemuSlirpNew(void) { g_autoptr(qemuSlirp) slirp =3D g_new0(qemuSlirp, 1); - if (!(slirp->features =3D virBitmapNew(QEMU_SLIRP_FEATURE_LAST))) - return NULL; - + slirp->features =3D virBitmapNew(QEMU_SLIRP_FEATURE_LAST); slirp->pid =3D (pid_t)-1; slirp->fd[0] =3D slirp->fd[1] =3D -1; diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index c2953c179b..47df102817 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -163,8 +163,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriverPtr dri= ver, if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) goto cleanup; - if (!(created =3D virBitmapNew(snapdef->ndisks))) - goto cleanup; + created =3D virBitmapNew(snapdef->ndisks); /* If reuse is true, then qemuSnapshotPrepare already * ensured that the new files exist, and it was up to the user to diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d582c207f4..af8fd03308 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1360,8 +1360,6 @@ testOpenDefault(virConnectPtr conn) } for (i =3D 0; i < 16; i++) { virBitmapPtr siblings =3D virBitmapNew(16); - if (!siblings) - goto error; ignore_value(virBitmapSetBit(siblings, i)); privconn->cells[i / 8].cpus[(i % 8)].id =3D i; privconn->cells[i / 8].cpus[(i % 8)].socket_id =3D i / 8; @@ -2788,8 +2786,7 @@ testDomainGetEmulatorPinInfo(virDomainPtr dom, } else if (def->cpumask) { cpumask =3D def->cpumask; } else { - if (!(bitmap =3D virBitmapNew(hostcpus))) - goto cleanup; + bitmap =3D virBitmapNew(hostcpus); virBitmapSetAll(bitmap); cpumask =3D bitmap; } @@ -2966,9 +2963,7 @@ static int testDomainGetVcpus(virDomainPtr domain, statbase =3D g_get_real_time(); hostcpus =3D VIR_NODEINFO_MAXCPUS(privconn->nodeInfo); - if (!(allcpumap =3D virBitmapNew(hostcpus))) - goto cleanup; - + allcpumap =3D virBitmapNew(hostcpus); virBitmapSetAll(allcpumap); /* Clamp to actual number of vcpus */ @@ -3081,8 +3076,7 @@ testDomainGetVcpuPinInfo(virDomainPtr dom, if (!(def =3D virDomainObjGetOneDef(privdom, flags))) goto cleanup; - if (!(hostcpus =3D virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo)= ))) - goto cleanup; + hostcpus =3D virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo)); virBitmapSetAll(hostcpus); ret =3D virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumap= s, diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 1bff5d4ae6..74d1883d94 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -433,8 +433,7 @@ virBitmapParseSeparator(const char *str, size_t i; int start, last; - if (!(*bitmap =3D virBitmapNew(bitmapSize))) - return -1; + *bitmap =3D virBitmapNew(bitmapSize); if (!str) goto error; @@ -664,10 +663,7 @@ virBitmapParseUnlimited(const char *str) virBitmapPtr virBitmapNewCopy(virBitmapPtr src) { - virBitmapPtr dst; - - if ((dst =3D virBitmapNew(src->nbits)) =3D=3D NULL) - return NULL; + virBitmapPtr dst =3D virBitmapNew(src->nbits); if (virBitmapCopy(dst, src) !=3D 0) { virBitmapFree(dst); @@ -699,8 +695,6 @@ virBitmapNewData(const void *data, const unsigned char *bytes =3D data; bitmap =3D virBitmapNew(len * CHAR_BIT); - if (!bitmap) - return NULL; /* le64toh is not available, so we do the conversion by hand */ p =3D bitmap->map; @@ -1115,8 +1109,6 @@ virBitmapNewString(const char *string) } bitmap =3D virBitmapNew(len * 4); - if (!bitmap) - return NULL; for (i =3D 0; i < len; i++) { unsigned long nibble =3D g_ascii_xdigit_value(string[len - i - 1]); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 76f7eb9a3d..31c8c79fb3 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -571,8 +571,7 @@ virCommandMassClose(virCommandPtr cmd, return -1; } - if (!(fds =3D virBitmapNew(openmax))) - return -1; + fds =3D virBitmapNew(openmax); # ifdef __linux__ if (virCommandMassCloseGetFDsLinux(cmd, fds) < 0) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index f60577b221..44aa7ad95d 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -768,14 +768,9 @@ dnsmasqCapsNewEmpty(const char *binaryPath) return NULL; if (!(caps =3D virObjectNew(dnsmasqCapsClass))) return NULL; - if (!(caps->flags =3D virBitmapNew(DNSMASQ_CAPS_LAST))) - goto error; + caps->flags =3D virBitmapNew(DNSMASQ_CAPS_LAST); caps->binaryPath =3D g_strdup(binaryPath ? binaryPath : DNSMASQ); return caps; - - error: - virObjectUnref(caps); - return NULL; } dnsmasqCapsPtr diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index c00a393def..28f032b972 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -268,8 +268,7 @@ virHostCPUGetSiblingsList(unsigned int cpu) if (rv =3D=3D -2) { /* If the file doesn't exist, the threadis its only sibling */ ret =3D virBitmapNew(cpu + 1); - if (ret) - ignore_value(virBitmapSetBit(ret, cpu)); + ignore_value(virBitmapSetBit(ret, cpu)); } return ret; @@ -332,8 +331,7 @@ virHostCPUParseNode(const char *node, goto cleanup; /* Keep track of the CPUs that belong to the current node */ - if (!(node_cpus_map =3D virBitmapNew(npresent_cpus))) - goto cleanup; + node_cpus_map =3D virBitmapNew(npresent_cpus); /* enumerate sockets in the node */ sockets_map =3D virBitmapNew(0); @@ -1119,9 +1117,7 @@ virHostCPUGetAvailableCPUsBitmap(void) if ((hostcpus =3D virHostCPUGetCount()) < 0) return NULL; - if (!(bitmap =3D virBitmapNew(hostcpus))) - return NULL; - + bitmap =3D virBitmapNew(hostcpus); virBitmapSetAll(bitmap); } diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index c43823c747..76aeeba22a 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3331,8 +3331,7 @@ virNetDevGetFeatures(const char *ifname, struct ifreq ifr; VIR_AUTOCLOSE fd =3D -1; - if (!(*out =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST))) - return -1; + *out =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST); if ((fd =3D virNetDevSetupControl(ifname, &ifr)) < 0) return -1; diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 5a1218cdf2..6728f62a87 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -273,8 +273,7 @@ virNumaGetNodeCPUs(int node, return -2; } - if (!(cpumap =3D virBitmapNew(max_n_cpus))) - return -1; + cpumap =3D virBitmapNew(max_n_cpus); for (i =3D 0; i < max_n_cpus; i++) { if (MASK_CPU_ISSET(mask, i)) { @@ -1027,8 +1026,7 @@ virNumaGetHostMemoryNodeset(void) if (maxnode < 0) return NULL; - if (!(nodeset =3D virBitmapNew(maxnode + 1))) - return NULL; + nodeset =3D virBitmapNew(maxnode + 1); for (i =3D 0; i <=3D maxnode; i++) { if (!virNumaNodeIsAvailable(i)) diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 2d34b617a6..f450740318 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -70,13 +70,9 @@ virPortAllocatorNew(void) if (!(pa =3D virObjectLockableNew(virPortAllocatorClass))) return NULL; - if (!(pa->bitmap =3D virBitmapNew(VIR_PORT_ALLOCATOR_NUM_PORTS))) - goto error; + pa->bitmap =3D virBitmapNew(VIR_PORT_ALLOCATOR_NUM_PORTS); return pa; - error: - virObjectUnref(pa); - return NULL; } static int diff --git a/src/util/virprocess.c b/src/util/virprocess.c index e9df563896..d379f7446f 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -520,8 +520,7 @@ virProcessGetAffinity(pid_t pid) goto cleanup; } - if (!(ret =3D virBitmapNew(ncpus))) - goto cleanup; + ret =3D virBitmapNew(ncpus); for (i =3D 0; i < ncpus; i++) { /* coverity[overrun-local] */ @@ -580,8 +579,7 @@ virProcessGetAffinity(pid_t pid) return NULL; } - if (!(ret =3D virBitmapNew(sizeof(mask) * 8))) - return NULL; + ret =3D virBitmapNew(sizeof(mask) * 8); for (i =3D 0; i < sizeof(mask) * 8; i++) if (CPU_ISSET(i, &mask)) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 2d945ff934..dabfa9990e 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1157,13 +1157,9 @@ virResctrlAllocUpdateMask(virResctrlAllocPtr alloc, cache - a_type->nmasks + 1) < 0) return -1; - if (!a_type->masks[cache]) { + if (!a_type->masks[cache]) a_type->masks[cache] =3D virBitmapNew(virBitmapSize(mask)); - if (!a_type->masks[cache]) - return -1; - } - return virBitmapCopy(a_type->masks[cache], mask); } @@ -1874,8 +1870,6 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info) virBitmapFree(mask); mask =3D virBitmapNew(i_type->bits); - if (!mask) - goto error; virBitmapSetAll(mask); for (k =3D 0; k <=3D i_type->max_cache_id; k++) { @@ -2102,8 +2096,6 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc, } a_mask =3D virBitmapNew(i_type->bits); - if (!a_mask) - return -1; for (i =3D last_pos; i < last_pos + need_bits; i++) ignore_value(virBitmapSetBit(a_mask, i)); diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 229de14935..a669b4ca99 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -852,8 +852,7 @@ qcow2GetFeatures(virBitmapPtr *features, if (len < QCOW2v3_HDR_SIZE) return -1; - if (!(feat =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) - return -1; + feat =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); /* todo: check for incompatible or autoclear features? */ bits =3D virReadBufInt64BE(buf + QCOW2v3_HDR_FEATURES_COMPATIBLE); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 4b1b04c6e1..fa4e685d97 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1509,8 +1509,6 @@ virVMXParseConfig(virVMXContext *ctx, size_t naffs; def->cpumask =3D virBitmapNew(VIR_DOMAIN_CPUMASK_LEN); - if (!def->cpumask) - goto cleanup; if (!(afflist =3D virStringSplitCount(sched_cpu_affinity, ",", 0, = &naffs))) goto cleanup; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 3e7d55c50b..3e2f8ee01c 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1481,8 +1481,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom, return -1; if (strlen(buf) =3D=3D 0) { - if (!(def->cpumask =3D virBitmapNew(hostcpus))) - return -1; + def->cpumask =3D virBitmapNew(hostcpus); virBitmapSetAll(def->cpumask); } else { if (virBitmapParse(buf, &def->cpumask, hostcpus) < 0) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index a0dcbba07b..3973c762f0 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2252,9 +2252,6 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabil= ities(const void *opaque) } bitmap =3D virBitmapNew(QEMU_MIGRATION_CAP_LAST); - if (!bitmap) - goto cleanup; - ignore_value(virBitmapSetBit(bitmap, QEMU_MIGRATION_CAP_XBZRLE)); if (!(json =3D qemuMigrationCapsToJSON(bitmap, bitmap))) goto cleanup; diff --git a/tests/testutils.c b/tests/testutils.c index b747f65eea..2e586e98bf 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -832,8 +832,7 @@ int virTestMain(int argc, } } - if (!(failedTests =3D virBitmapNew(1))) - return EXIT_FAILURE; + failedTests =3D virBitmapNew(1); ret =3D (func)(); @@ -980,9 +979,7 @@ virTestCapsBuildNUMATopology(int seq) cell_cpus[core_id].id =3D id + core_id; cell_cpus[core_id].socket_id =3D cell_id + seq; cell_cpus[core_id].core_id =3D id + core_id; - if (!(cell_cpus[core_id].siblings =3D - virBitmapNew(MAX_CPUS_IN_CELL))) - goto error; + cell_cpus[core_id].siblings =3D virBitmapNew(MAX_CPUS_IN_CELL); ignore_value(virBitmapSetBit(cell_cpus[core_id].siblings, id)); } id++; @@ -997,10 +994,6 @@ virTestCapsBuildNUMATopology(int seq) } return g_steal_pointer(&caps); - - error: - VIR_FREE(cell_cpus); - return NULL; } static virDomainDefParserConfig virTestGenericDomainDefParserConfig =3D { diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 255492c9e8..5d2f1b0bad 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -36,8 +36,7 @@ test1(const void *data G_GNUC_UNUSED) size =3D 1024; bit =3D 100; - if (!(bitmap =3D virBitmapNew(size))) - return -1; + bitmap =3D virBitmapNew(size); if (virBitmapSetBit(bitmap, bit) < 0) return -1; @@ -140,8 +139,7 @@ test3(const void *data G_GNUC_UNUSED) int size =3D 5; size_t i; - if ((bitmap =3D virBitmapNew(size)) =3D=3D NULL) - return -1; + bitmap =3D virBitmapNew(size); for (i =3D 0; i < size; i++) ignore_value(virBitmapSetBit(bitmap, i)); @@ -195,8 +193,6 @@ test4(const void *data G_GNUC_UNUSED) /* 1. zero set */ bitmap =3D virBitmapNew(size); - if (!bitmap) - return -1; if (virBitmapNextSetBit(bitmap, -1) !=3D -1) return -1; @@ -337,8 +333,6 @@ test6(const void *v G_GNUC_UNUSED) int size =3D 64; bitmap =3D virBitmapNew(size); - if (!bitmap) - return -1; str =3D virBitmapFormat(bitmap); if (!str) @@ -416,8 +410,6 @@ test7(const void *v G_GNUC_UNUSED) for (i =3D 0; i < nmaxBit; i++) { g_autoptr(virBitmap) bitmap =3D virBitmapNew(maxBit[i]); - if (!bitmap) - return -1; if (virBitmapIsAllSet(bitmap)) return -1; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dfcba04682..b5e7d8f705 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6840,8 +6840,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, if (curvcpus =3D=3D 0) curvcpus =3D maxvcpus; - if (!(ret =3D virBitmapNew(maxvcpus))) - goto cleanup; + ret =3D virBitmapNew(maxvcpus); if ((nnodes =3D virXPathNodeSet("/domain/vcpus/vcpu", ctxt, &nodes)) <= =3D 0) { /* if the specific vcpu state is missing provide a fallback */ @@ -7118,8 +7117,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen, virBitmapPtr map =3D NULL; if (cpulist[0] =3D=3D 'r') { - if (!(map =3D virBitmapNew(maxcpu))) - return NULL; + map =3D virBitmapNew(maxcpu); virBitmapSetAll(map); } else { int lastcpu; @@ -11989,8 +11987,7 @@ virshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2) if (n1_child_size =3D=3D 0 && n2_child_size =3D=3D 0) return true; - if (!(bitmap =3D virBitmapNew(n1_child_size))) - return false; + bitmap =3D virBitmapNew(n1_child_size); child2 =3D n2->children; while (child2) { --=20 2.26.2