Skip to content

Commit

Permalink
Addresssanitizer: Fix buffer overflow in test_bitset_getset (#210)
Browse files Browse the repository at this point in the history
Fix buffer overflow in bitset test case
  • Loading branch information
sriganes authored and kevyang committed Jan 9, 2019
1 parent abaf93a commit 0c0caa7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/data_structure/bitmap/check_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#define BUF_SIZE 32

#define NCOL1 64
static uint16_t cols[4] = { 0, 7, 29, 42 };
#define COLS_SIZE 4
static uint16_t cols[COLS_SIZE] = { 0, 7, 29, 42 };

static uint8_t buf[BUF_SIZE];
static struct bitset *bs = (struct bitset *)buf;
Expand Down Expand Up @@ -43,7 +44,7 @@ START_TEST(test_bitset_getset)
int i, j;

bitset_init(bs, NCOL1);
for (i = 0, j = 0; i < NCOL1; i++) {
for (i = 0, j = 0; i < NCOL1 && j < COLS_SIZE; i++) {
if (i == cols[j]) {
bitset_set(bs, i, 1);
j++;
Expand All @@ -53,7 +54,7 @@ START_TEST(test_bitset_getset)
}
}

for (j=0; j < 4; j++) { /* set these bits back to 0 */
for (j = 0; j < COLS_SIZE; j++) { /* set these bits back to 0 */
ck_assert_int_eq(bitset_get(bs, cols[j]), 1);
bitset_set(bs, cols[j], 0);
ck_assert_int_eq(bitset_get(bs, cols[j]), 0);
Expand Down

0 comments on commit 0c0caa7

Please sign in to comment.