aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-01-25 20:21:18 +0100
committerStefano Brivio <sbrivio@redhat.com>2022-01-26 16:30:59 +0100
commitcaa22aa644cb56e6fda77ff80c62d038653f3cf9 (patch)
tree07616ecc3704c24d235591e1efce6fb1031f49b2 /util.c
parent4c7304db85bd4e8ae641ab946a5b3832f24b6eca (diff)
downloadpasst-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.gz
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.bz2
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.lz
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.xz
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.tar.zst
passt-caa22aa644cb56e6fda77ff80c62d038653f3cf9.zip
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>
Diffstat (limited to 'util.c')
-rw-r--r--util.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/util.c b/util.c
index 7a3ea51..46a539b 100644
--- a/util.c
+++ b/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);
}
/**