3 ms·
I think of segfaults as being caused by accessing an out-of-bounds index in an array, personally. Yes, you can do the same thing by dereferencing NULL, but in
by thaumasiotes 13y ago
I think of segfaults as being caused by accessing an out-of-bounds index in an array, personally. Yes, you can do the same thing by dereferencing NULL, but in my (university only) experience, overrunning an array came up much more often.
- lubomir 13y agoIn C it is quite common for functions to indicate failure by returning NULL. Not checking for these errors is another very common reason for segfaults.
- kabouseng 13y agoIn C, accessing an out of bounds array index does not necessarily cause a segmentation fault. It's called buffer overrun and regularly used in malicious exploits / attacks. What does occur many times is you mess up your stack, or mess with other memory in your heap, causing segmentation faults for various other reasons.