diff options
author | Martin Mikkelsen <mamikk@mamikk.no> | 2015-07-31 19:01:34 +0200 |
---|---|---|
committer | Martin Mikkelsen <mamikk@mamikk.no> | 2015-07-31 19:08:26 +0200 |
commit | 951c3eefacedcdbdb2cebf245f043aa3e81fb483 (patch) | |
tree | 7b691ecac11e1591bd2949f3fa333d73dd338db7 /src/test/test-bitmap.c | |
parent | d5fa81995849cb263ecfcd0aa6ab661360d9213e (diff) |
bitmap: make bitmap_clear free the bitmap array
Given two bitmaps and the following code:
Bitmap *a = bitmap_new(), *b = bitmap_new();
bitmap_set(a, 1);
bitmap_clear(a);
bitmap_set(a, 0);
bitmap_set(b, 0);
These two bitmaps should now have the same bits set and they should be
equal but bitmap_equal() will return false in this case because while
bitmap_clear() resets the number of elements in the array it does not
clear the array and bitmap_set() expects the array to be cleared.
GREEDY_REALLOC0 looks at the allocated size and not the actual size so
it does not clear any memory.
Fix this by freeing the allocated memory and resetting the whole Bitmap
to an initial state in bitmap_clear().
This also adds test code for this issue.
Diffstat (limited to 'src/test/test-bitmap.c')
-rw-r--r-- | src/test/test-bitmap.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/test/test-bitmap.c b/src/test/test-bitmap.c index cb9e4a41f6..ff22117745 100644 --- a/src/test/test-bitmap.c +++ b/src/test/test-bitmap.c @@ -111,5 +111,13 @@ int main(int argc, const char *argv[]) { bitmap_unset(b, 0); assert_se(bitmap_equal(b, b2)); + assert_se(bitmap_set(b, 1) == 0); + bitmap_clear(b); + assert_se(bitmap_equal(b, b2)); + + assert_se(bitmap_set(b, 0) == 0); + assert_se(bitmap_set(b2, 0) == 0); + assert_se(bitmap_equal(b, b2)); + return 0; } |