Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug794.cpp

1    #define NULL 0
2    struct Basket
3        {
4        int Value;
5        Basket *NextBasket;
6        };
7    Basket *InsertBasket(
8        Basket *FirstBasketInList, Basket *NewBasket )
9        {
10       Basket *BasketInList   = FirstBasketInList;
11       Basket *PreviousBasket = NULL;
12       while( BasketInList->Value <= NewBasket->Value )
13           {
14           PreviousBasket = BasketInList;
15           BasketInList   = BasketInList->NextBasket;
16           }
17       PreviousBasket->NextBasket = NewBasket;
18       NewBasket->NextBasket      = BasketInList;
19       return FirstBasketInList;
20       }

The Easter Bunny is using this program to sort out his Easter baskets; but it turns out he's not much of a programmer. There's a bug. Can you spot it?


bug794.cpp lint Output

--- Module:   bug794.cpp (C++)
                                          _
    PreviousBasket->NextBasket = NewBasket;
bug794.cpp(17) : Info 794: Conceivable use of null pointer 'PreviousBasket' in
    left argument to operator '->' [Reference: file bug794.cpp: line 11]

Reference Manual Explanation


794    Conceivable use of null pointer 'Symbol' in [left/right] argument
       to operator 'String'  Reference -- From information gleaned from
       earlier statements it is conceivable that a null pointer (a
       pointer whose value is 0) can be used in a context where null
       pointers are inappropriate.  In the case of binary operators one
       of the words 'left' or 'right' is used to designate which operand
       is null.  Symbol identifies the pointer variable that may be
       NULL.  This is similar to messages 413 and 613 and differs from
       them in that the likelihood is not as great.  For example:

                 int *p = 0;
                 int i;
                 for( i = 0; i < n; i++ )
                     p = &a[i];
                 *p = 0;

       If the body of the for loop is never taken then p remains null.


If you have comments or questions about this bug, please post them to our   Discussion Forum


Previous Bug - Bug #1411 - March 2008

Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2009, Gimpel Software, All rights reserved.