[splint-discuss] How to check Uninitialized variable
Ian Moor
iwm at doc.ic.ac.uk
Tue May 12 05:51:41 PDT 2009
Vijayendra Suman wrote:
> Hello All,
>
> Thanks for the prompt response,
>
> Here is the small piece of code this is compilable
>
> 1 #include <stdio.h>
> 2 void Call(int *a)
> 3 {
> 4 int StatusUpdate;
> 5 int MyOne()
> 6 {
> 7 printf("One \n");
> 8 return 1;
> 9 }
> 10 int MyTwo()
> 11 {
> 12 printf("Two \n");
> 13 return 2;
> 14 }
> 15 if (a==NULL) return;
> 16 if (*a == 1 )
> 17 StatusUpdate = MyOne();
> 18 else
> 19 StatusUpdate = MyTwo();
> 20 }
> 21
> 22 int main(int argc, char * argv[])
> 23 {
> 24 int call; /* call is not initialized */
> 25 Call(&call);
> 26 return 0;
> 27 }
>
> I compiled using
> gcc -o my my.c -Wall
>
> Problem definition:
> int call; /* call is not initialized */
> The call variable is not initialized, Even with -Wall i do not get any
> warnings.
>
In the gcc manual the section about the -Wuninitialized option
it says:
These warnings are possible only in optimizing compilation, because they
require data flow information that is computed only when optimizing. If
you do not specify -O, you will not get these warnings.
So gcc can be made to report uninitialized variables.
More information about the splint-discuss
mailing list