util: Avoid return of possibly truncated unsigned long in bitmap_isset()
Oops. If *word & BITMAP_BIT(bit) is bigger than an int (which is the case for half of the possible bits of a bitmap on 64-bit archs), we'll return that as an int, that is, zero, even if the bit at hand is set. Just return zero or one there, no callers are interested in the actual bitmap as return value. Issue found as pasta wouldn't automatically detect some bound ports. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
154216d483
commit
80283e6aea
1 changed files with 2 additions and 2 deletions
4
util.c
4
util.c
|
@ -366,13 +366,13 @@ void bitmap_clear(uint8_t *map, int bit)
|
||||||
* @map: Pointer to bitmap
|
* @map: Pointer to bitmap
|
||||||
* @bit: Bit number to check
|
* @bit: Bit number to check
|
||||||
*
|
*
|
||||||
* Return: non-zero if given bit is set, zero if it's not
|
* Return: one if given bit is set, zero if it's not
|
||||||
*/
|
*/
|
||||||
int bitmap_isset(const uint8_t *map, int bit)
|
int bitmap_isset(const uint8_t *map, int bit)
|
||||||
{
|
{
|
||||||
unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
|
unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
|
||||||
|
|
||||||
return *word & BITMAP_BIT(bit);
|
return !!(*word & BITMAP_BIT(bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue