As far as I understand, a segfault is raised whenever a program attempts to access unauthorized memory.
The following code allocates a one-int memory block to p
, and then tries to write at some unknown address.
#include <stdlib.h>
int main(void)
{
int* p = malloc(sizeof(int));
p[1000] = 12;
return 0;
}
Why does this code raise no segmentation fault, while it tries to access this somewhat random address?
Related
How undefined is undefined behavior? - Explains undefined behaviours, but not why that p[1000] = 12
instruction does not raise a segfault.