Click on image to see enlargment

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

            bug774.c

1    #include <stdio.h>
2    char Cheryl[] = "gbgbbgbbgggb";
3
4    int main()
5        {
6        char *p;
7        int naughty = 0;
8
9        for( p = Cheryl; *p; p++ )
10           {
11           int previous = 'g';  /* previous behavior was 'g' */
12
13           if( *p == 'b' && previous == 'b' ) naughty++;
14           else if( *p == 'b' ) previous = 'b';
15           else previous = 'g';
16           }
17       if( naughty ) printf( "Cheryl has been naughty\n" );
18       return 0;
19       }

In Santa's new program to determine who was naughty and who was nice, good months are encoded with 'g' and bad months with 'b' and naughty is defined as two consecutive bad months. So why is the program not regarding Cheryl as being naughty?


bug774.c lint Output

--- Module:   bug774.c (C)
                                         _
        if( *p == 'b' && previous == 'b' ) naughty++;
bug774.c(13) : Info 774: Boolean within 'if' always evaluates to False
    [Reference: file bug774.c: lines 11, 13]

Reference Manual Explanation


774    Boolean within 'String' always evaluates to [True/False]  -- The
       indicated clause (String is one of if, while or for (2nd
       expression)) has an argument that appears to always evaluate to
       either 'True' or 'False' (as indicated in the message).
       Information is gleaned from a variety of sources including prior
       assignment statements and initializers.  Compare this with
       message 506 which is based on testing constants or combinations
       of constants.  Also compare with the Elective Note 944 which can
       sometimes provide more detailed information.
       See 9.2 Value Tracking


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


Previous Bug - Bug #662 - November 2006

[ new ] 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 2007, Gimpel Software, All rights reserved.