Extract the clearing of the traling bits from 'virBitmapSetAll' into a new helper. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virbitmap.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 7dc63da6db..35cf729a22 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -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); } -- 2.47.0