469,642 Members | 1,298 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

"Implicitly only" splint warnings

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
---

Anyone knows what's wrong with my code ?
Thanks for your help,
Guy.

Nov 14 '05 #1
2 4731
Guy Eschemann wrote:
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
---

Anyone knows what's wrong with my code ?


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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #2
Thanks a lot, that was very helpful !
Guy.

Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Arne Kösling | last post: by
267 posts views Thread by Xah Lee | last post: by
3 posts views Thread by Rahul Babbar | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.