Click on image to see enlargment

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

            bug687.cpp

1    #include <string.h>
2    struct deer_data
3        {
4        char *name; // deer name
5        double no2; // nitrous oxide emissions
6        double ch4; // methane emissions
7        double co2; // co2 emissions;
8        };
9    // the co2 equivalent of one reindeer's emissions
10   double co2( deer_data *p )
11       {
12       double total = p->co2;
13       if( strcmp( p->name, "Rudolph" ) == 0 )
14           total += 1.,   // energy surcharge?
15       total += p->no2 * 297.4;
16       total += p->ch4 * 23.2;
17       return total;
18       }

The UN commission on climate requested that Santa measure green house gas emissions from his reindeer. After gathering the data (phew, what a job) and running this program, he got strange results for non-Rudolph reindeer. Can you spot the problem?


bug687.cpp lint Output

--- Module:   bug687.cpp (C++)
                           _
    total += p->no2 * 297.4;
bug687.cpp(15) : Warning 687: Suspicious use of comma
    _
    }
bug687.cpp(18) : Info 818: Pointer parameter 'p' (line 10) could be declared as pointing to const

Reference Manual Explanation


687    Suspicious use of comma operator  -- A comma operator appeared unbraced and
       unparenthesized in a statement following an if, else, while or for clause.
       For example:

                 if( n > 0 ) n = 1,
                 n = 2;

       Thus the comma could be mistaken for a semi-colon and hence be the source of
       subtle bugs.

       If the statement is enclosed in curly braces or if the expression is enclosed
       in parentheses, the message is not issued.


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


Previous Bug - Bug #591 - November 2009

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.