[splint-discuss] How do I treat a symbol table?
Terry Colligan
terry-splint at tenberry.com
Tue Aug 23 13:02:37 EDT 2005
I'm new to splint, and can't seem to solve a number of
problems. I've been reading (and re-reading) the manual, but
I can't quite see the big picture.
One of my problems is how to treat a symbol table. I need
mostly to add malloc'd copies of strings to the symbol table,
but the symbol table is initialized with some string literals.
The code:
// test to show splint problem
// enough declarations to keep splint happy
typedef struct key key;
key *this_key;
// make entry in table
void add_entry(key *p, // lookup key
/*@null@*//*@keep@*/char *value) // value for hey
{
// whatever, including making entry in symbol table structure
// (enough code to solve not-used issues)
if (p)
if (value)
;
else ;
else if (value)
;
}
// remember entry if appropriate
void remember(bool appropriate, // decision to add
char *value) // value to add
{
if (appropriate)
add_entry(this_key, value);
}
// make static entry
void initialize(void)
{
add_entry(this_key, "Built-in Symbol");
}
The result:
~/C$ splint -ifempty test.c
Splint 3.1.1 --- 21 Aug 2005
test.c: (in function remember)
test.c:26:3: Variable value is kept in true branch, but not kept in
continuation.
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)
test.c:26:3: in true branch:
test.c:26:23: Storage value becomes kept
test.c: (in function initialize)
test.c:33:22: Unqualified static storage "Built-in Symbol" passed as keep
param: add_entry (..., "Built-in Symbol")
Static storage is transferred in an inconsistent way. (Use -statictrans to
inhibit warning)
Finished checking --- 2 code warnings
I added the /*@keep@*/ annotation to add_entry() to resolve
warnings where splint (correctly, it seems to me) was worried
that storage was being lost.
Do I misunderstand what /*@keep@*/ is for?
Can somebody suggest an alternative?
I don't really want to turn off 'branchstate' or 'statictrans'
in general -- I want to solve this issue so I don't have to
turn off major checking areas.
Thanks for considering my problem.
--
Terry
Terry Colligan terry-splint at tenberry.com
Tenberry Software, Inc. http://www.tenberry.com
info at tenberry.com phone 1.480.767.8868 fax 1.480.767.8709
More information about the splint-discuss
mailing list