I am trying to replace VC2010 default runtime calloc with my own implementation of calloc
I tried this code but my program still uses the default VC2010 calloc
void* calloc(size_t num, size_t size) {
// Calculate the total size. Check for potential overflow.
if (size * num / num != size) { // Basic overflow check. More robust checks are possible.
return NULL; // Or handle the error in another way.
}
size_t total_size = num * size;
// Allocate memory using malloc.
void* ptr = malloc(total_size);
// If allocation fails, return NULL.
if (ptr == NULL) {
return NULL;
}
// Zero out the allocated memory using memset.
memset(ptr, 0, total_size);
return ptr;
}