Click on image to see enlargment

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

            bug530.cpp

1    #include <stdio.h>
2    #include <stdlib.h>
3    #include <string.h>
4    #define N 5
5    const char * const names[N] =
6        { "Red Sox", "Yankees", "Giants",
7          "Rangers", "Phillies" /* etc. */ };
8    void find_name( char *x )
9        {
10       x = (char *)malloc(100);
11       if( !x ) exit(1);
12       strcpy( x, names[ rand() % N ] );
13       }
14   int main()
15       {
16       char *x;
17       find_name(x);
18       printf( "%s\n", x );
19       free(x);
20       return 0;
21       }

It's the start of the baseball season and Joe's program to find the name of a random baseball team does not seem to be working as it produced no output. Why not?


bu530.cpp lint Output

--- Module:   bug530.cpp (C++)
    _
    }
bug530.cpp(13) : Warning 429: Custodial pointer 'x' (line 8) has not been freed or returned
                _
    find_name(x);
bug530.cpp(17) : Warning 530: Symbol 'x' (line 16) not initialized 

Reference Manual Explanation


530  Symbol 'Symbol' (Location) not initialized -- An auto variable was used before it was initialized.



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


Previous Bug - Bug #1571 - March 2011

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