1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-02-14 05:57:26 +03:00

util: virbitmap: Extract clearing of unused bits at the end of the last unit

Extract the clearing of the traling bits from 'virBitmapSetAll' into a
new helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Peter Krempa 2024-10-17 13:47:25 +02:00
parent e572150ebe
commit e506e0b3f1

View File

@ -757,6 +757,19 @@ virBitmapSize(virBitmap *bitmap)
}
/**
* Internal helper that clears the unused bits at the end of the last bitmap unit.
*/
static void
virBitmapClearTail(virBitmap *bitmap)
{
size_t tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
if (tail)
bitmap->map[bitmap->map_len - 1] &= -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
}
/**
* virBitmapSetAll:
* @bitmap: the bitmap
@ -765,15 +778,10 @@ virBitmapSize(virBitmap *bitmap)
*/
void virBitmapSetAll(virBitmap *bitmap)
{
int tail = bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT;
memset(bitmap->map, 0xff,
bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT));
/* Ensure tail bits are clear. */
if (tail)
bitmap->map[bitmap->map_len - 1] &=
-1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail);
virBitmapClearTail(bitmap);
}