File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
regression/cbmc-library/alloca-02 Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdlib.h>
2
+
3
+ #ifdef _WIN32
4
+ void * alloca (size_t alloca_size );
5
+ #endif
6
+
7
+ int * foo ()
8
+ {
9
+ int * foo_ptr = alloca (sizeof (int ));
10
+ return foo_ptr ;
11
+ }
12
+
13
+ int main ()
14
+ {
15
+ int * from_foo = foo ();
16
+ * from_foo = 42 ; // access to object that has gone out of scope
17
+
18
+ return 0 ;
19
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --pointer-check
4
+ dereference failure: dead object in \*from_foo: FAILURE$
5
+ ^\*\* 1 of 6 failed
6
+ ^VERIFICATION FAILED$
7
+ ^EXIT=10$
8
+ ^SIGNAL=0$
9
+ --
10
+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -2115,6 +2115,28 @@ void goto_checkt::goto_check(
2115
2115
std::move (lhs), std::move (rhs), i.source_location ));
2116
2116
t->code_nonconst ().add_source_location () = i.source_location ;
2117
2117
}
2118
+
2119
+ if (
2120
+ variable.type ().id () == ID_pointer &&
2121
+ function_identifier != " alloca" &&
2122
+ (ns.lookup (variable.get_identifier ()).base_name ==
2123
+ " return_value___builtin_alloca" ||
2124
+ ns.lookup (variable.get_identifier ()).base_name ==
2125
+ " return_value_alloca" ))
2126
+ {
2127
+ // mark pointer to alloca result as dead
2128
+ exprt lhs = ns.lookup (CPROVER_PREFIX " dead_object" ).symbol_expr ();
2129
+ exprt alloca_result =
2130
+ typecast_exprt::conditional_cast (variable, lhs.type ());
2131
+ if_exprt rhs (
2132
+ side_effect_expr_nondett (bool_typet (), i.source_location ),
2133
+ std::move (alloca_result),
2134
+ lhs);
2135
+ goto_programt::targett t =
2136
+ new_code.add (goto_programt::make_assignment (
2137
+ std::move (lhs), std::move (rhs), i.source_location ));
2138
+ t->code_nonconst ().add_source_location () = i.source_location ;
2139
+ }
2118
2140
}
2119
2141
}
2120
2142
else if (i.is_end_function ())
You can’t perform that action at this time.
0 commit comments