virBitmapIsBitSet: Allow NULL bitmap

The virBitmapIsBitSet API is a permissive one which returns false when
the bit is not set or is out of range. We can do the same if the bitmap
is NULL to aid certain situations when this can happen, but we don't
want to add extra checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Peter Krempa 2022-11-09 16:54:56 +01:00
parent 9598c3c684
commit f836947a91
2 changed files with 3 additions and 3 deletions

View File

@ -216,7 +216,7 @@ virBitmapIsSet(virBitmap *bitmap, size_t b)
/**
* virBitmapIsBitSet:
* @bitmap: Pointer to bitmap
* @bitmap: Pointer to bitmap (May be NULL)
* @b: bit position to get
*
* Get setting of bit position @b in @bitmap.
@ -228,7 +228,7 @@ bool
virBitmapIsBitSet(virBitmap *bitmap,
size_t b)
{
if (bitmap->nbits <= b)
if (!bitmap || bitmap->nbits <= b)
return false;
return virBitmapIsSet(bitmap, b);

View File

@ -61,7 +61,7 @@ void virBitmapClearBitExpand(virBitmap *bitmap, size_t b)
* Get bit @b in @bitmap. Returns false if b is out of range.
*/
bool virBitmapIsBitSet(virBitmap *bitmap, size_t b)
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
G_GNUC_WARN_UNUSED_RESULT;
/*
* Get setting of bit position @b in @bitmap and store in @result
*/