3 ms·
Is that an almost correct piece of code? What sort of situation would something like that come up in?
by elnate 13y ago
Is that an almost correct piece of code? What sort of situation would something like that come up in?
- gizmo686 13y agoEvery hear of segfaults? They are almost always the result of de-referencing NULL.
- thaumasiotes 13y agoI 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.