Skip to content
Snippets Groups Projects
Commit 97bd98cb authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

rework malloc mock function

parent ae4e1246
Branches
Tags
1 merge request!26Adapt cmp_tool to the chunk decompression
......@@ -35,13 +35,16 @@ static int malloc_fail;
void* malloc(size_t size)
{
static void* (*real_malloc)(size_t) = NULL;
static void* (*real_malloc)(size_t size) = NULL;
if(malloc_fail)
return NULL;
if (!real_malloc)
real_malloc = (void *(*)(size_t))dlsym(RTLD_NEXT, "malloc");
if (!real_malloc) {
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
/* The cast removes a gcc warning https://stackoverflow.com/a/31528674 */
TEST_ASSERT_NOT_NULL(real_malloc);
}
fprintf(stderr, "malloc(%zu)\n", size);
return real_malloc(size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment