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

            bug613.cpp

1     int count( char *, char );
2
3     int main( int argc, char **argv)
4         {
5         char *p = argv[1];
6         if( argc > 1 && p ) ;else return count( p, 'e' );
7         return 0;
8         }
9
10    // count( buf, letter ) counts the number of letters in buf
11    int count( char *buf, char letter )
12        {
13        int n = 0;
14        char *p;
15        for( p = buf; *p; p++ )
16            { if( *p == letter ) n++; }
17        return n;
18        }

Why is this program producing garbage?


bug613.cpp lint Output

--- Module:   bug613.cpp
    _
    }
bug613.cpp  8  Info 818: Pointer parameter 'argv' (line 3) could be declared as
    pointing to const

During Specific Walk:
  File bug613.cpp line 6: count(0?, 101)
bug613.cpp  15  Warning 613: Possible use of null pointer 'p' in argument to
    operator 'unary *' [Reference: file bug613.cpp: line 6]

During Specific Walk:
  File bug613.cpp line 6: count(0?, 101)
bug613.cpp  15  Warning 613: Possible use of null pointer 'p' in argument to
    operator 'unary *' [Reference: file bug613.cpp: line 6]

During Specific Walk:
  File bug613.cpp line 6: count(0?, 101)
bug613.cpp  16  Warning 613: Possible use of null pointer 'p' in argument to
    operator 'unary *' [Reference: file bug613.cpp: line 6]

During Specific Walk:
  File bug613.cpp line 6: count(0?, 101)
bug613.cpp  15  Warning 613: Possible use of null pointer 'p' in argument to
    operator '++' [Reference: file bug613.cpp: line 6]


Reference Manual Explanation

 
613   Possible use of null pointer 'Symbol' in [left/right]
      argument to operator 'String' Reference  -- From
      information gleaned from earlier statements, it is
      possible that a null pointer (a pointer whose value is 0)
      can be used in a context where null pointers are
      inappropriate.  Such contexts include:  Unary *, pointer
      increment (++) or decrement(--), addition of pointer to
      numeric, and subtraction of two pointers.  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.  See
      also messages  413 and  794.

Previous Bug - Bug #648 - January 2002

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software