lkml.org 
[lkml]   [2003]   [Jul]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: Style question: Should one check for NULL pointers?
    Hi,

    On Thu, Jul 10, 2003 at 04:28:09PM -0400, Alan Stern wrote:
    > There are many places in the kernel where a function checks whether a
    > pointers it has been given is NULL. Now sometimes this makes perfect
    > sense because the function's description explicitly says that a NULL
    > pointer argument is valid. But in many, many cases (maybe even the
    > majority) it is nothing more than paranoia: the pointer can never be NULL
    > in a properly functioning system.

    There are many meanings of NULL.

    a) NULL -> I don't know
    Reaction: Ok, then do a generic/default variant.

    b) NULL -> failure in caller passed down to us.
    Reaction: Pass it on, return -EINVAL or ignore the call

    c) NULL -> failure in API (argument can't be NULL)
    Reaction: BUG_ON()

    ...

    So the answer isn't only taste, it's a matter of simplicity and
    roboustness.

    Regards

    Ingo Oeser
    -
    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/

    \
     
     \ /
      Last update: 2005-03-22 13:46    [W:3.074 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site