[lkml]   [2003]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: Style question: Should one check for NULL pointers?
    On Fri, 11 Jul 2003, Eli Carter wrote:

    > > Not really needed, since a segfault will produce almost as much
    > > information as a BUG_ON(). Certainly it will produce enough to let a
    > > developer know that the pointer was NULL.
    > Your first message said, "I see no reason for pure paranoia,
    > particularly if it's not commented as such." A BUG_ON() call makes it
    > clear that the condition should never happen. Dereferencing a NULL
    > leaves the question of whether NULL is an unhandled case or invalid
    > input. BUG_ON() is an explicit paranoia check, and with a bit of
    > preprocessing magic, you could compile out all of those checks.
    > So it documents invalid input conditions, allows you to eliminate the
    > checks in the name of speed or your personal preference, or use them to
    > help with debugging/testing.

    Okay, that makes sense. Particularly the debugging and testing part. And
    for an excellent example of _documented_ paranoia, see the source to

    But if you look very far through the kernel sources you will see many
    occurrences of code similar to this:

    static void release(struct xxx *ptr)
    if (!ptr)

    I can't see any reason for keeping something like that.

    Alan Stern

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:46    [W:0.020 / U:206.920 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site