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

            bug530.cpp

1    #include <stdio.h>
2    #include <stdlib.h>
3    #include <string.h>
4
5    void foo( char *x )
6        {
7        x = (char *)malloc(100);
8        if( !x ) exit(1);
9        strcpy( x, "this is a test" );
10       }
11
12   int main()
13       {
14       char *x;
15
16       foo(x);
17       printf( "string = %s\n", x );
18       free(x);
19       return 0;
20       }

To the bewilderment of the programmer the expected output did not appear. Why not?
Thanks to Jimmy Yu for submitting this one.


bug530.cpp lint Output

--- Module:   bug530.cpp
    _
    }
bug530.cpp(10) : Warning 429: Custodial pointer 'x' (line 5) has not been freed
    or returned 
          _
    foo(x);
bug530.cpp(16) : Warning 530: x (line 14) not initialized


Reference Manual Explanation

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


Previous Bug - Bug #722 - November 2000

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright © 2003, Gimpel Software