diff options
author | Tom Gundersen <teg@jklm.no> | 2015-07-17 18:30:41 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-07-17 18:59:16 +0200 |
commit | cdf6f5ae0465a8fb25d2afc758911985cc542a07 (patch) | |
tree | fd6a99b9ee96ffdd378d46d16770cedb02b96ae0 /src/basic | |
parent | 511ed7991737dc567bef51a8051a1a577fa18e05 (diff) |
basic: bitmap - complete fix for bitshift overflow
The bug found by David existed in several places, fix them all. Also
extend the tests to cover these cases.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/bitmap.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c index c5039fd22f..0747749d13 100644 --- a/src/basic/bitmap.c +++ b/src/basic/bitmap.c @@ -69,7 +69,7 @@ int bitmap_ensure_allocated(Bitmap **b) { } int bitmap_set(Bitmap *b, unsigned n) { - long long bitmask; + long long unsigned bitmask; unsigned offset; assert(b); @@ -87,7 +87,7 @@ int bitmap_set(Bitmap *b, unsigned n) { b->n_bitmaps = offset + 1; } - bitmask = 1 << BITMAP_NUM_TO_REM(n); + bitmask = 1ULL << BITMAP_NUM_TO_REM(n); b->bitmaps[offset] |= bitmask; @@ -95,7 +95,7 @@ int bitmap_set(Bitmap *b, unsigned n) { } void bitmap_unset(Bitmap *b, unsigned n) { - long long bitmask; + long long unsigned bitmask; unsigned offset; assert(b); @@ -105,13 +105,13 @@ void bitmap_unset(Bitmap *b, unsigned n) { if (offset >= b->n_bitmaps) return; - bitmask = 1 << BITMAP_NUM_TO_REM(n); + bitmask = 1ULL << BITMAP_NUM_TO_REM(n); b->bitmaps[offset] &= ~bitmask; } bool bitmap_isset(Bitmap *b, unsigned n) { - long long bitmask; + long long unsigned bitmask; unsigned offset; if (!b || !b->bitmaps) @@ -122,7 +122,7 @@ bool bitmap_isset(Bitmap *b, unsigned n) { if (offset >= b->n_bitmaps) return false; - bitmask = 1 << BITMAP_NUM_TO_REM(n); + bitmask = 1ULL << BITMAP_NUM_TO_REM(n); return !!(b->bitmaps[offset] & bitmask); } @@ -149,7 +149,7 @@ void bitmap_clear(Bitmap *b) { } bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) { - long long bitmask; + long long unsigned bitmask; unsigned offset, rem; if (!b || i->idx == BITMAP_END) |