From nobody Thu May 15 03:38:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517556235759122.12988533562611; Thu, 1 Feb 2018 23:23:55 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id F2A6C3680C; Fri, 2 Feb 2018 07:23:49 +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 A1FCB6BF99; Fri, 2 Feb 2018 07:23:49 +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 6417941FAE; Fri, 2 Feb 2018 07:23:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w127Nf23008575 for ; Fri, 2 Feb 2018 02:23:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id AAB67619EE; Fri, 2 Feb 2018 07:23:41 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C89C619EA for ; Fri, 2 Feb 2018 07:23:39 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 07725120487 for ; Fri, 2 Feb 2018 08:23:38 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Fri, 2 Feb 2018 08:23:33 +0100 Message-Id: <39cb274bf7e8f18b1141dcb05cb7116ddf304538.1517556148.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] util: Clear unused part of the map in virBitmapShrink X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Feb 2018 07:23:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some of the other functions depend on the fact that unused bits and longs a= re always zero and it's less error-prone to clear it than fix the other functi= ons. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1540817 Signed-off-by: Martin Kletzander --- src/util/virbitmap.c | 13 +++++++++++++ tests/virbitmaptest.c | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index b2c5c7a6a5ac..b32342024e19 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1213,9 +1213,22 @@ void virBitmapShrink(virBitmapPtr map, size_t b) { + size_t nl =3D 0; + size_t nb =3D 0; + if (!map) return; =20 if (map->max_bit >=3D b) map->max_bit =3D b; + + nl =3D map->max_bit / VIR_BITMAP_BITS_PER_UNIT; + nb =3D map->max_bit % VIR_BITMAP_BITS_PER_UNIT; + map->map[nl] &=3D ((1UL << nb) - 1); + + nl++; + if (nl < map->map_len) { + memset(map->map + nl, 0, + (map->map_len - nl) * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT)= ); + } } diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 9c0ffe70cb49..a3258dc0ebad 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -656,6 +656,11 @@ test12(const void *opaque ATTRIBUTE_UNUSED) =20 TEST_MAP(1024, "34,1023"); =20 + virBitmapShrink(map, 35); + TEST_MAP(35, "34"); + virBitmapShrink(map, 34); + TEST_MAP(34, ""); + ret =3D 0; =20 cleanup: --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list