Skip to content

Commit

Permalink
malloc wrappers in test cases: fix handling of failed realloc()
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Jan 20, 2020
1 parent 2519119 commit fc2b498
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/common/malloc_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ void* realloc_with_check(void *ptr, size_t size)
assert(alloc_count > 0);

buf = realloc(buf, size + GUARD_SIZE);
if (!buf)
{
if (DEBUG_MALLOC) fprintf(stderr, "Realloc 0x%04x/%u to %u failed\n", (unsigned)(uintptr_t)ptr, (unsigned)oldsize, (unsigned)size);
return NULL;
}

((size_t*)buf)[0] = size;
((size_t*)buf)[1] = CHECK1;
((size_t*)(buf + size))[2] = CHECK2;
Expand Down

0 comments on commit fc2b498

Please sign in to comment.