I read a unit test, that checks for invalid free or double-free:
int main() {
char *a = (char*) my_malloc(200);
char *b = (char*) my_malloc(50);
char *c = (char*) my_malloc(200);
char *p = (char*) my_malloc(3000);
(void) a, (void) c;
memcpy(p, b - 200, 450);
my_free(p + 200);
printstatistics();
}
Why do we need to cast char*
to void
and what happens in memory when we do this cast?