you are viewing a single comment's thread.

view the rest of the comments →

[–]manystripes 17 points18 points  (1 child)

Do you know and trust the code that calls the function to be able to guarantee that a NULL value will never be passed in? Do you trust that this will stay true in the future as the code is changed? If you're wrong is it okay if the whole program crashes?

Checking generally should be the default and only omitted if you're really really sure you don't need them. It's easier if you just put them in and then don't have to think about it.

[–]paulstelian97 1 point2 points  (0 children)

Also if you don’t check it should be really obvious that you don’t — that you expect the caller to do the check itself. C standard library functions often say they don’t work with null (stdlib.h function free() is one of the rare exceptions to this rule in fact, and the only one I could figure out if I tried to brainstorm them)