mirror of
https://passt.top/passt
synced 2025-08-11 09:53:12 +02:00
tcp, udp, util: Fixes for bitmap handling on big-endian, casts
Bitmap manipulating functions would otherwise refer to inconsistent sets of bits on big-endian architectures. While at it, fix up a couple of casts. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
4c7304db85
commit
caa22aa644
5 changed files with 16 additions and 7 deletions
12
util.c
12
util.c
|
@ -342,7 +342,9 @@ int timespec_diff_ms(struct timespec *a, struct timespec *b)
|
|||
*/
|
||||
void bitmap_set(uint8_t *map, int bit)
|
||||
{
|
||||
map[bit / 8] |= 1 << (bit % 8);
|
||||
unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
|
||||
|
||||
*word |= BITMAP_BIT(bit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -352,7 +354,9 @@ void bitmap_set(uint8_t *map, int bit)
|
|||
*/
|
||||
void bitmap_clear(uint8_t *map, int bit)
|
||||
{
|
||||
map[bit / 8] &= ~(1 << (bit % 8));
|
||||
unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
|
||||
|
||||
*word &= ~BITMAP_BIT(bit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,7 +368,9 @@ void bitmap_clear(uint8_t *map, int bit)
|
|||
*/
|
||||
int bitmap_isset(const uint8_t *map, int bit)
|
||||
{
|
||||
return map[bit / 8] & (1 << bit % 8);
|
||||
unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
|
||||
|
||||
return *word & BITMAP_BIT(bit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue