[splint-discuss] how to annotate a pointer to static memory returned by a function

Jorge Peixoto de Morais Neto please.no.spam.here at gmail.com
Sun Mar 4 05:01:23 EST 2007


static char *statictest(){
  static char buff[10];
  return buff;
}
int main(){
  /*@unused@*/
  char *p=statictest();
  return 0;
}
When the above program is fed to  splint, the following output results:
statictest.c: (in function statictest)
statictest.c:3:10: Unqualified static storage buff returned as implicitly
only:
                      buff
  Static storage is transferred in an inconsistent way. (Use -statictrans to
  inhibit warning)
statictest.c: (in function main)
statictest.c:8:12: Fresh storage p not released before return
  A memory leak has been detected. Storage allocated locally is not released
  before the last reference to it is lost. (Use -mustfreefresh to inhibit
  warning)
   statictest.c:7:24: Fresh storage p created

Finished checking --- 2 code warnings

How can I correctly annotate the code to avoid this? I couldn't find in the
manual.

Thank you in advance.

-- 
Software is like sex: it is better when it is free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cs.Virginia.EDU/pipermail/splint-discuss/attachments/20070304/f47c2f57/attachment.htm


More information about the splint-discuss mailing list