summaryrefslogtreecommitdiff
path: root/lib/bitmap.c
diff options
context:
space:
mode:
authorZhengLingyun <konghuarukhr@163.com>2013-07-08 14:10:26 -0700
committerBen Pfaff <blp@nicira.com>2013-07-08 14:16:21 -0700
commita6913ea8529fb9dc7386ce5407027dc5745250eb (patch)
tree07c41adae60613f28366fe8a1ea1aa474c424036 /lib/bitmap.c
parentea401d9ace433e73f2cdd05dfde5debf506b6c5d (diff)
downloadopenvswitch-a6913ea8529fb9dc7386ce5407027dc5745250eb.tar.gz
bitmap: Fix bitmap_allocate1() bug when n_bits is a multiple of 32.
In function bitmap_allocate1(), the last "unsigned long" in bitmap was set to all 0-bits when (n_bits % BITMAP_ULONG_BITS == 0). This commit correctly sets it to all 1-bits. Signed-off-by: ZhengLingyun <konghuarukhr@163.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index d607526d5..ac568e97b 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -24,6 +24,7 @@ bitmap_allocate1(size_t n_bits)
{
size_t n_bytes = bitmap_n_bytes(n_bits);
size_t n_longs = bitmap_n_longs(n_bits);
+ size_t r_bits = n_bits % BITMAP_ULONG_BITS;
unsigned long *bitmap;
/* Allocate and initialize most of the bitmap. */
@@ -32,7 +33,9 @@ bitmap_allocate1(size_t n_bits)
/* Ensure that the last "unsigned long" in the bitmap only has as many
* 1-bits as there actually should be. */
- bitmap[n_longs - 1] = (1UL << (n_bits % BITMAP_ULONG_BITS)) - 1;
+ if (r_bits) {
+ bitmap[n_longs - 1] = (1UL << r_bits) - 1;
+ }
return bitmap;
}