3 ms·
Abort and terminate? Jokes aside, error checking in c is important since if you don't do it you get "On error resume next" behavior.
by strictfp 13y ago
Abort and terminate? Jokes aside, error checking in c is important since if you don't do it you get "On error resume next" behavior.
- geocar 13y agoWhat does malloc() return if it fails? volatile char *x = 0; And what happens if you write to that address? *x = 69; The answers to these questions, whilst not defined by the C language, are portable enough.
- emillon 13y agoThe difference is in the error message you get. Adding "if (x == NULL) abort()" will display a backtrace near the error. To understand the cause of the segfault, you will have to follow the data flow in your favorite debugger.
- clarry 13y agoWhat about the more common situation where the thing to be allocated is a (potentially large) array? These aren't always accessed sequentially. And the offset might be (indirectly) controlled by untrusted data from the wild.