/*@globals undef a@*/ means that splint should assume a is not defined
when the function is entered.  So, what you want in this case is:

static /*@checkedstrict@*/ int a;

static void s() /*@globals a@*/
{
  if(a==34) a=33;
}

int main(void) /*@globals undef a@*/
{
  int r;
  if(r==66) r = 65;
  s();
  return 0;
}

which reports a warning as it is (but not if you assign to a before the
call to s().)

Note I added the /*@checkedstrict@*/ annotation to the declaration of a so
splint will report warnings for functions that use a but do not declare it
in their globals list.  This isn't necessary for the warning to be
reported, but without the /*@globals a@*/ in the declaration of s there
would be no warning.

--- Dave

On Tue, 13 Aug 2002, Massimiliano Cialdi wrote:

> David Evans wrote:
> >
> > The only way to get warnings for uninitalized non-local variables is by
> > using annotations (/*@globals undef a@*/).  In the example you have, its
> > simple enough to do a flow analysis to see that a is used before it is
> > initialized, but in general doing that type of global flow analysis is
> > expensive.
>
> I tried with:
> ------------------------------
> static int a;
> static void s()
> /*@globals undef a;@*/
> {
>   if(a==34) a=33;
> }
>
> int main(void)
> /*@globals a;@*/
> {
>   int r;
>   if(r==66)
>     r = 65;
>   a=3;
>   s();
>   return 0;
> }
> -------------------------------
>
> but splint response was :
> a.c: (in function s)
> a.c:8:6: Undef global a used before definition
>   An rvalue is used that may not be initialized to a value on some
> execution
>   path. (Use -usedef to inhibit warning)
> a.c: (in function main)
> a.c:15:6: Variable r used before definition
>
> a is initialize in main() but splint does not recognize this case!
>
> I must analyze a very complex set of source code files, and I hope that
> splint could help me without instrument code.
>
> thanks
> --
> Massimiliano Cialdi
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>

Reply via email to