Newer versions of GCC are too "smart" and replace a call to malloc(X)
followed by a call to memset(0,X) with a call co calloc(), which obviously
results in an infinite loop when it does that in our own calloc()
implementation. Using `volatile` for the variable storing the total size
prevents the optimization and we actually call malloc().
HOOK(void*, calloc, size_t nmemb, size_t size)
{
void *ptr;
+ volatile size_t total;
- size *= nmemb;
- ptr = malloc(size);
- memset(ptr, 0, size);
+ total = nmemb * size;
+ ptr = malloc(total);
+ memset(ptr, 0, total);
return ptr;
}