"Implicitly only" splint warnings

G

Guy Eschemann

When running the following code through splint, I get two warnings that
I don't fully understand.

This is the code :

---
typedef struct
{
int *pData;
} t_MyStruct;

static t_MyStruct myStruct =
{
(void *)0
};

static int myData = 0;

void process(void)
{
myStruct.pData = &myData;
}
---

And here are the warnings :

---
Splint 3.1.1 --- 12 April 2003

< loading standard library C:\Programme\splint-3.1.1\lib\standard.lcd
..... >
< preprocessing >
< checking test.c >
test.c: (in function process)
test.c(16,3): Implicitly only storage myStruct.pData (type int *) not
released
before assignment: myStruct.pData = &myData
A memory leak has been detected. Only-qualified storage is not
released
before the last reference to it is lost. (Use -mustfreeonly to
inhibit
warning)
test.c(16,3): Immediate address &myData assigned to implicitly only:
myStruct.pData = &myData
An immediate address (result of & operator) is transferred
inconsistently.
(Use -immediatetrans to inhibit warning)
< global checks >

Finished checking --- 2 code warnings
 
M

Michael Mair

Guy said:
When running the following code through splint, I get two warnings that
I don't fully understand.

This is the code :

---
typedef struct
{
int *pData;
} t_MyStruct;

static t_MyStruct myStruct =
{
(void *)0
splint will warn you about this, as well if you do not give
/*@null@*/ comments.
};

static int myData = 0;

void process(void)
{
myStruct.pData = &myData;

Well, why is this ugly?

1. You may lose the only pointer to the storage pData is pointing
to. In this case, this does not happen, as myStruct.pData is a null
pointer at first and afterwards, you will not do anything -- but you
do not control it.
2. splint seems to think that you would be better of if making a copy.
}
---

And here are the warnings :

---
Splint 3.1.1 --- 12 April 2003

< loading standard library C:\Programme\splint-3.1.1\lib\standard.lcd
.... >
< preprocessing >
< checking test.c >
test.c: (in function process)
test.c(16,3): Implicitly only storage myStruct.pData (type int *) not
released
before assignment: myStruct.pData = &myData
A memory leak has been detected. Only-qualified storage is not
released
before the last reference to it is lost. (Use -mustfreeonly to
inhibit
warning)
test.c(16,3): Immediate address &myData assigned to implicitly only:
myStruct.pData = &myData
An immediate address (result of & operator) is transferred
inconsistently.
(Use -immediatetrans to inhibit warning)
< global checks >

Finished checking --- 2 code warnings

Your "problems" stem from the "only" qualification splint assumes;
IIRC, splint has a huge manual where you hopefully can find a way
that the member pData is not /*@only@*/.

IMO, only 1. is a real problem. I would use assert(myStruct.pData==NULL)
to make sure that there is nothing to be overwritten if process() is
called only once. Otherwise, you would have to make sure that pData
is not the only pointer to allocated storage.


Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top