I believe that if you annotate p as being temp, i.e.,
/[EMAIL PROTECTED]@*/ char *p = buff;
then you're telling splint that p is a temporary
variable.
I can't confirm that this is correct, but I believe
it'll work.
Dave
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Terry Colligan
Sent: Wednesday, October 29, 2003 2:35 PM
To: [EMAIL PROTECTED]
Subject: [splint-discuss] Dealing with pointer functions that don't
allocate
A parsing idiom that I use a lot is to have a parsing function
return a pointer to the next place in the buffer. When running
splint on such a program, I get the following messages:
isspam.c: (in function isspam)
isspam.c:1961:17: 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)
isspam.c:1957:3: Fresh storage p created
isspam.c:1962:3: Clauses exit with p referencing fresh storage in while
body,
local storage if loop is not taken
The state of a variable is different depending on which branch is taken.
This
means no annotation can sensibly be applied to the storage.
(Use -branchstate
to inhibit warning)
isspam.c:1957:3: Fresh storage p created
Here is a reduced version of isspam:
int isspam(char *buff) // buffer to check for spam
{
char *p = buff;// current point in buffer
// parse each mail header
while (*p != '\0'*p != '\n')
{
p = parse_header(p); // this is line 1957 in above messages
// check for no headers at all
if ( xx )
return false;// this is line 1961 in above messages
}
The issue is that splint is treating 'parse_header' as a function
which returns a pointer to new storage, when in reality, it is just
returning a pointer to the same storage.
This is pointer-as-a-sequence, rather than pointer-as-an-object.
It seems I need to tell splint something about 'parse_header', but
I can't figure out what.
I've been reading the splint manual for a while, and looked on the mailing
list archives for the last several months, but I can't figure out how to
declare a function that takes a pointer arg, and returns a (possibly
incremented) value for that pointer.
Do I really have to disable these warnings? Or is there some way to
tell splint what is going on?
My .splintrc file:
-D__volatile=volatile
-warnposix
-exitarg
-predboolint
-exportlocal
-dependent-trans
-boolops
-compdef
-temptrans
-retvalint
-nullassign
-mustfreeonly
-onlytrans
-nullstate
-globstate
-nullpass
-observertrans
Any suggestions would be appreciated, even if it is only to say that
it can't be done.
--
Terry
Terry Colligan mailto:[EMAIL PROTECTED]
Tenberry Software, Inc. http://www.tenberry.com
[EMAIL PROTECTED] phone 1.480.767.8868 fax 1.480.767.8709
___
splint-discuss mailing list
[EMAIL PROTECTED]
http://www.splint.org/mailman/listinfo/splint-discuss
___
splint-discuss mailing list
[EMAIL PROTECTED]
http://www.splint.org/mailman/listinfo/splint-discuss