[splint-discuss] How to check Uninitialized variable

Ludolf Holzheid lholzheid at bihl-wiedemann.de
Tue May 12 05:32:04 PDT 2009


On Tue, 2009-05-12 16:52:44 +0530, Vijayendra Suman wrote:
> Hello All,
> 
> Thanks for the prompt response,
> 
> Here is the small piece of code this is compilable
> [..]

If you move the nested functions out of Call() like this:

>> #include <stdio.h>
>> 
>> static int MyOne(void)
>> {
>>    printf("One \n");
>>    return 1;
>> }
>> 
>> static int MyTwo(void)
>> {
>>    printf("Two \n");
>>    return 2;
>> }
>> 
>> static void Call(int *a)
>> {
>>   int StatusUpdate;
>>   if (a==NULL) return;
>>   if (*a == 1 )
>>     StatusUpdate = MyOne();
>>   else
>>     StatusUpdate = MyTwo();
>> }
>> 
>> int main(void)
>> {
>>  int call; /* call is not initialized */
>>   Call(&call);
>>    return 0;
>> }

and run the result through splint, you will get the following:

>> $ /c/Program\ Files/splint-3.1.1/bin/splint y.c
>> Splint 3.1.1 --- 12 April 2003
>> 
>> y.c: (in function main)
>> y.c(28,8): Passed storage &call not completely defined: Call (&call)
>>   Storage derivable from a parameter, return value or global is not
>>   defined.
>>   Use /*@out@*/ to denote passed or returned storage which need not be
>>   defined.
>>   (Use -compdef to inhibit warning)
>> 
>> Finished checking --- 1 code warning

That is, splint _does_ complain about using 'call' without prior
initialization.

Does this answer your question?

Ludolf

-- 

---------------------------------------------------------------
Ludolf Holzheid             Tel:    +49 621 339960
Bihl+Wiedemann GmbH         Fax:    +49 621 3392239
Floßwörthstraße 41          e-mail: lholzheid at bihl-wiedemann.de
D-68199 Mannheim, Germany
---------------------------------------------------------------



More information about the splint-discuss mailing list