Skip to content

Commit

Permalink
add test_buddy_realloc_ignore_01
Browse files Browse the repository at this point in the history
  • Loading branch information
spaskalev committed Nov 22, 2023
1 parent 52a2fdc commit be1c968
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,26 @@ void test_buddy_realloc_alignment(void) {
free(buddy_buf);
}

void test_buddy_realloc_ignore_01(void) {
unsigned char *buddy_buf = malloc(buddy_sizeof(4096));
unsigned char data_buf[4096];
struct buddy *buddy;
void *result;
unsigned char *ba;
start_test;
memset(data_buf, 0, 4096); /* make sure the buffer is empty */
buddy = buddy_init(buddy_buf, data_buf, 4096);
buddy_malloc(buddy, 64); /* allocate one slot */
result = buddy_malloc(buddy, 64); /* allocate its sibling */
memset(result, 255, 64); /* put some data in it */
result = buddy_realloc(buddy, result, 128, true); /* get a new slot, ignore data */
ba = (unsigned char *) result;
for (size_t i = 0; i < 64; i++) {
assert(ba[i] == 0);
}
free(buddy_buf);
}

void test_buddy_reallocarray_01(void) {
unsigned char *buddy_buf = malloc(buddy_sizeof(512));
unsigned char data_buf[512];
Expand Down Expand Up @@ -2392,6 +2412,8 @@ int main(void) {
test_buddy_realloc_08();
test_buddy_realloc_alignment();

test_buddy_realloc_ignore_01();

test_buddy_reallocarray_01();
test_buddy_reallocarray_02();
test_buddy_reallocarray_03();
Expand Down

0 comments on commit be1c968

Please sign in to comment.