int test_malloc(void **ptr, size_t size)
{
(*ptr) = malloc(size);
return 0;
}
int test_app()
{
char *data = NULL;
int ret = 0;
ret = test_malloc((void **)&data, 100);
}
Compiler: gcc 4.1.2
Among others, I am using -O2 & -Wall which are I think are turning on some options which checks for this.
You have a variable of type
char*, and intest_mallocyou are modifying it through an lvalue of typevoid *, which breaks strict aliasing rules.You could solve it like this:
But even better is to make test_malloc return
void*to avoid problems like this.