Skip to content

Commit eaa73cb

Browse files
committed
Default fall-through for function pointer removal
When the pointer points to neither of the candidates we shouldn't just call the first one (which does happen if the user does not request pointer-check). This PR inserts an ASSUME (false) which makes all subsequent assertions unreachable (and thus reported as not being violated). A small regression test is included.
1 parent 73be2ed commit eaa73cb

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// f is set to 0 -> does not point to either f1 or f2
2+
#include <assert.h>
3+
4+
typedef int (*f_ptr)(int);
5+
6+
extern f_ptr f;
7+
8+
int f1(int j);
9+
int f2(int i);
10+
11+
int f1(int j)
12+
{
13+
f = &f2;
14+
return 1;
15+
}
16+
int f2(int i)
17+
{
18+
assert(0);
19+
return 2;
20+
}
21+
22+
f_ptr f = 0;
23+
24+
int main()
25+
{
26+
int x = 0;
27+
28+
x = f(x);
29+
assert(x == 1);
30+
x = f(x);
31+
assert(x == 2);
32+
33+
return 0;
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[f2.assertion.1\] line [0-9]+ assertion 0: SUCCESS
7+
\[main.assertion.1\] line [0-9]+ assertion x == 1: SUCCESS
8+
\[main.assertion.2\] line [0-9]+ assertion x == 2: SUCCESS
9+
^VERIFICATION SUCCESSFUL$
10+
--
11+
^warning: ignoring

src/goto-programs/remove_function_pointers.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ void remove_function_pointerst::remove_function_pointer(
416416
t->source_location.set_property_class("pointer dereference");
417417
t->source_location.set_comment("invalid function pointer");
418418
}
419+
new_code_gotos.add(goto_programt::make_assumption(false_exprt()));
419420

420421
goto_programt new_code;
421422

0 commit comments

Comments
 (0)