Skip to content

Commit eac8e2c

Browse files
authored
Merge pull request #1009 from thk123/bugfix/arrays-structs-null-pointers
Fix for arrays containing structs will null pointers
2 parents 3c896fd + 8ec1890 commit eac8e2c

File tree

39 files changed

+124
-19
lines changed

39 files changed

+124
-19
lines changed

regression/goto-analyzer/approx-array-variable-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed (long )*long int\)i\] == f8 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed (long )*long int\)i\] == f9 THEN GOTO [0-9]$
1616
^warning: ignoring
17+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-cast-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1616
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
17+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-const-fp-with-null/test.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ main.c
55
^\s*IF fp == f2 THEN GOTO [0-9]$
66
^\s*IF fp == f3 THEN GOTO [0-9]$
77
^\s*IF fp == f4 THEN GOTO [0-9]$
8+
replacing function pointer by 3 possible targets
89
^SIGNAL=0$
910
--
1011
^warning: ignoring
@@ -14,3 +15,4 @@ main.c
1415
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1516
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1617
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
18+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1616
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
17+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-const-pointer-const-struct-non-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1616
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
17+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-const-struct-non-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1616
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
17+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/approx-const-fp-array-variable-invalid-cast-const-fp/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ main.c
1414
^\s*IF fp_tbl\[\(signed long int\)i\] == f7 THEN GOTO [0-9]$
1515
^\s*IF fp_tbl\[\(signed long int\)i\] == f8 THEN GOTO [0-9]$
1616
^\s*IF fp_tbl\[\(signed long int\)i\] == f9 THEN GOTO [0-9]$
17+
function \w+: replacing function pointer by 9 possible targets
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i\n", 1); }
4+
void f2 (void) { printf("%i\n", 2); }
5+
void f3 (void) { printf("%i\n", 3); }
6+
void f4 (void) { printf("%i\n", 4); }
7+
void f5 (void) { printf("%i\n", 5); }
8+
void f6 (void) { printf("%i\n", 6); }
9+
void f7 (void) { printf("%i\n", 7); }
10+
void f8 (void) { printf("%i\n", 8); }
11+
void f9 (void) { printf("%i\n", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
struct action
16+
{
17+
int x;
18+
void_fp fun;
19+
};
20+
21+
// Array with an empty final element
22+
const struct action fp_tbl[5] = {{1, f2}, {2, f3} ,{3, f4},};
23+
24+
// There is a basic check that excludes all functions that aren't used anywhere
25+
// This ensures that check can't work in this example
26+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
27+
28+
void func(int i)
29+
{
30+
const void_fp fp = fp_tbl[i].fun;
31+
fp();
32+
}
33+
34+
int main()
35+
{
36+
for(int i=0;i<3;i++)
37+
{
38+
func(i);
39+
}
40+
41+
return 0;
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --verbosity 10 --pointer-check
4+
^Removing function pointers and virtual functions$
5+
^\s*IF fp == f2 THEN GOTO [0-9]$
6+
^\s*IF fp == f3 THEN GOTO [0-9]$
7+
^\s*IF fp == f4 THEN GOTO [0-9]$
8+
^\s*ASSERT FALSE // invalid function pointer$
9+
^SIGNAL=0$
10+
--
11+
^warning: ignoring
12+
^\s*IF fp == f1 THEN GOTO [0-9]$
13+
^\s*IF fp == f5 THEN GOTO [0-9]$
14+
^\s*IF fp == f6 THEN GOTO [0-9]$
15+
^\s*IF fp == f7 THEN GOTO [0-9]$
16+
^\s*IF fp == f8 THEN GOTO [0-9]$
17+
^\s*IF fp == f9 THEN GOTO [0-9]$
18+
function \w+: replacing function pointer by 9 possible targets

regression/goto-analyzer/no-match-array-literal-const-fp-null/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ main.c
44
^Removing function pointers and virtual functions$
55
^\s*ASSERT FALSE // invalid function pointer$
66
^SIGNAL=0$
7+
function func: replacing function pointer by 0 possible targets
78
--
89
^warning: ignoring

0 commit comments

Comments
 (0)