Re: Style question: Should one check for NULL pointers?

David D. Hagood (wowbagger@sktc.net)
Fri, 11 Jul 2003 09:13:03 -0500


Hua Zhong wrote:

> Not always true. In some cases you know how to handle: just return
> without doing anyting.

That is NOT an error condition - the API specifically allows NULL to be
passed in, and specifically states that no action will be taken in that
case.

But consider the following code:

sscanf(0,0);

That IS an error condition - both the string to scan and the format
string are NULL. In this case sscanf should return EITHER 0 (no items
matched) or better still -1 (error).

As others have said - ideally, if you have any doubt about a new
function you are writing being able to succeed, you should write it to
return a success report.

However, my whole point was that simply checking for null and doing
nothing when null was not a valid value was violating the rule of "don't
check if you don't know how to handle".

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/