lkml.org 
[lkml]   [2003]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: Style question: Should one check for NULL pointers?
    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/

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