Hacker News new | past | comments | ask | show | jobs | submit login

Is that an almost correct piece of code? What sort of situation would something like that come up in?



Every hear of segfaults? They are almost always the result of de-referencing NULL.


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.


In 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.


In 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: