[splint-discuss] RE: Help on "Storage x may become null" error

Wenzel, Bodo wenzel at bbr-vt.de
Fri Apr 20 03:29:54 EDT 2007


Thanks! Please don't feel offended, but we better spend time to solve 
problems, not to fill gaps ;-) Your attachment was scrubbed from the 
digest I received, but there is a link to it. I'm sorry to reply so 
slowly, but my employer limits the time spend with non-profit 
stuff...

These are my results and ideas:

First, I ran splint with the contents shown below. To reduce the 
size, I have "condensed" the source a bit... As you reported, it 
complaints about
"Null storage listOfMyOwnType[1] derivable from parameter", but on
"initializeItem1 (&listOfMyOwnType[1])", not on useMyOwnList!
It shows the correct row/column where
"Storage listOfMyOwnType[1] becomes null."

Second, I added "/*@out@*/" just before the parameter of the 
prototype of "initializeItem1", AFAIK there's no need to repeat it at 
the definition of the function. Now splint reports no warnings.

Concerning the annotation for pointers to MY_OWN_TYPE; I think if you 
add "/*@null@*/" to listOfMyOwnType, it declares that symbol as 
possibly NULL. MY_OWN_TYPE*[] it is compatible to MY_OWN_TYPE**, and 
splint seems not to distinguish these. So, to annotate the elements, 
I suggest to "typedef /*@null@*/ MY_OWN_TYPE *MY_OWN_TYPE_POINTER;" 
and to declare "MY_OWN_TYPE_POINTER listOfMyOwnType[2];". Anyway, 
initializeItem1 needs the annotation at its parameter.

You don't need to "return;" at the end of a "void" typed function. 
However, your coding convention might require this. To reduce the 
size of the exmaple source even more, the called function can be 
declared as global, and their definition omitted.

BTW, my splint says "Splint 3.1.1 --- 12 April 2003" and it's running 
on Win2K.

--- test*.c ------------------------------------------

typedef struct
{
  int a;
  int b;
  char c;
} MY_OWN_TYPE;

static MY_OWN_TYPE gAType;

static void initializeItem1( MY_OWN_TYPE ** ptrToItemInList );
static void useMyOwnList( MY_OWN_TYPE ** list );

void init( void )
{
  MY_OWN_TYPE * listOfMyOwnType[2];

  listOfMyOwnType[0] = &gAType;
  listOfMyOwnType[1] = NULL; 

  initializeItem1( &listOfMyOwnType[1] );

  useMyOwnList( listOfMyOwnType );
}

static void initializeItem1( MY_OWN_TYPE ** ptrToItemInList )
{
  static MY_OWN_TYPE item1;

  *ptrToItemInList = &item1;
}

static void useMyOwnList( MY_OWN_TYPE ** list )
{
  MY_OWN_TYPE * item;

  item = list[0];
}

With regards,
Bodo Wenzel
- Software Development -

-- 
BBR - Baudis Bergmann Rösch
Verkehrstechnik GmbH
Pillaustraße 1e	
D - 38126 Braunschweig

T: +49.531.27300-766
F: +49.531.27300-999
@: wenzel at bbr-vt.de
W: http://www.bbr-vt.de

Registergericht:   
AG Braunschweig  HRB 3037

Geschäftsführer: 
Dipl.-Ing. Arne Baudis
Dipl.-Ing. Thomas Bergmann
Dipl.-Ing. Frank-Michael Rösch

USt.-ID-Nr.:
DE 114 877 881




More information about the splint-discuss mailing list