Click on image to see enlargment

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

            bug809.cpp

1    #include <stdio.h>
2    #include <string.h>
3    enum type { H=1 /* herbivore */, C=2 /* carnivore */,
4                S=4 /* sweet tooth */, D=8 /* Drinker */ };
5    //lint -e655 -e641  inhibit warnings about using enum's as integers
6    char *dish( int x )
7        {
8        char buf[100]; char *p = buf; *p = 0;
9        if( x & D ) strcat( p, "rum-soaked " );
10       if( x & S ) strcat( p, "sugared " );
11       if( x & C ) strcat( p, "turkey " );
12       if( x & H ) strcat( p, "broccoli " );
13       return p;
14    }
15   int main()
16       {
17       printf( "please pass the %s and the %s.",
18           dish(C|S), dish(H|D) );
19       return 0;
20       }

Our cook decided to automate Thanksgiving dinner by running this little program to take into account the eccentricities of our guests. But something is going quite wrong. What is it?


bug809.cpp lint Output

--- Module: bug809.cpp
        _
return p;
bug809.cpp(13) : Info 809: Possible return of address of auto through variable 'p'

Reference Manual Explanation

809   Possible return of address of auto through variable 'Symbol'  -- The value
      held by a pointer variable may have been the address of an auto variable.  
      It is normally incorrect to return the address of an item on the stack because 
      the portion of the stack allocated to the returning function is subject to 
      being obliterated after return.

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

Previous Bug - Bug #806 - October 2004

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