Click on image to see enlargment

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

            bug414.cpp

1    #include <stdio.h>
2    #include <string.h>
3
4    void print( const char * );
5    int main()
6        {
7        print( "Mitt Romney" );
8        print( "Newt Gingrich" );
9        print( "Rick Santorum" );
10       print( "Ron Paul" );
11       return 0;
12       }
13   void print( const char *name )
14       {
15       int indent = 100 / (strlen(name) - 8) / 2;
16       for( int i = 0; i < indent; i++ )
17           printf( " " );
18       printf( "%s\n", name );
19       }

A news organization had hired a programmer of questionable competence to produce reports on the campaign for the Republican nomination. The program somehow failed to print the name of "Ron Paul". Can you spot the problem?


bug414.cpp lint Output

--- Module:   bug414.cpp (C++)
                                          _
    int indent = 100 / (strlen(name) - 8) / 2;
bug414.cpp(15) : Info 834: Operator '/' followed by operator '/' is confusing. Use parentheses.

During Specific Walk:
  File bug414.cpp line 10: print(!=0) #3
bug414.cpp(15) : Warning 414: Possible division by 0 [Reference: file bug414.cpp: lines 10, 15]

Reference Manual Explanation


 414   Possible division by 0  -- The second argument to either the division operator (/) or the
       modulus operator (%) may be zero.  Information is taken from earlier statements including
       assignments, initialization and tests.


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


Previous Bug - Bug #559 - January 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.