Menu

#6 false positives with pointer / array of array

open
nobody
None
5
2008-04-15
2008-04-15
No

From http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=475675
From: Helmut Grohne <helmut@subdivi.de>

Declaring

struct foo *(bar[baz]);

makes splint spit out tons of warnings when accessing bar[qux]->quux,
because it thinks foo is of type struct foo * whereas it really is
struct foo **. This behaviour is wrong and makes checking some files
almost impossible.

Helmut

Test case ...

$ cat foo.c
#define NUM 10

struct foo {
int var;
};

struct bar {
int var;
};

int main()
{
struct foo *(f[NUM]);
struct bar (*b[NUM]);
f[0]->var = 0;
b[0]->var = 0;
return 0;
}
$
$ splint foo.c
Splint 3.1.2 --- 10 Apr 2008

foo.c: (in function main)
foo.c:15:2: Variable f used before definition
An rvalue is used that may not be initialized to a value on some execution
path. (Use -usedef to inhibit warning)
foo.c:15:6: Arrow access of non-pointer (struct foo): f[0]->var
Types are incompatible. (Use -type to inhibit warning)
foo.c:16:2: Array fetch from non-array (struct bar): b[0]

Finished checking --- 3 code warnings

Discussion


Log in to post a comment.