Bad pointers and invalid memory access in C