Click on image to see enlargment

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

            bug413.cpp

1    #include <stdio.h>
2    extern char *score_cards[];
3    //  count(buf,ch) counts ch in buf. if buf is
4    //  NULL, report the total count since last NULL
5    int count( char *buf, char ch )
6        {
7        static int total = 0;
8        int n;
9        char *p;
10       if( buf )
11           { n = total; total = 0; return n; }
12       for( p = buf; *p; p++ )
13           if( *p == ch ) total++;
14       return 0;
15       }
16   int main()
17       {
18       int i;
19       char *s;
20       for( i = 0; ; i++ )
21           {
22           if( (s = score_cards[i]) )
23               (void) count( s, 'K' );
24           else break;
25           }
26       printf( "found %d strikeouts\n", count( 0, ' ') );
27       return 0;
28       }

Archie, a fantasy baseball enthusiast, is preparing to do a computer analysis of all of last year's score cards. This program is intended to find the total number of strikeouts ("K"s) recorded. But something's going wrong.


bug413.cpp lint Output

--- Module:   bug413.cpp (C++)
                    _
    for( p = buf; *p; p++ )
bug413.cpp(12) : Warning 413: Likely use of null pointer 'p' in argument to operator 'unary *'
    [Reference: file bug413.cpp: lines 10, 12]
                     _
        if( *p == ch ) total++;
bug413.cpp(13) : Warning 613: Possible use of null pointer 'p' in argument to operator 'unary *'
    [Reference: file bug413.cpp: lines 10, 12]

bug413.cpp(12) : Warning 613: Possible use of null pointer 'p' in argument to operator '++'
    [Reference: file bug413.cpp: lines 10, 12]
                                 _
        if( (s = score_cards[i]) )
bug413.cpp(22) : Info 820: Boolean test of a parenthesized assignment

Reference Manual Explanation


413    Likely use of null pointer 'Symbol' in [left/right] argument to operator 'String' Reference  -- From
       information gleaned from earlier statements, it appears certain that a null pointer (a pointer whose
       value is 0) has been used in a context where null pointers are inappropriate.  These 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.


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


Previous Bug - Bug #415 - March 2012

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 2012, Gimpel Software, All rights reserved.