Skip to content

Commit feb1108

Browse files
committed
Fix pointer-invalidation bug in ansi-c/padding.cpp
The insert on line 262 invalidates the iterators of the vector which is being iterated, which may cause the reference on line 206 to dangle. This in turn leads to undefined behaviour on line 269 when the reference is passed to a function. The fix is to take a copy instead of a reference on line 206.
1 parent 5813937 commit feb1108

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ansi-c/padding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void add_padding(struct_typet &type, const namespacet &ns)
203203
it!=components.end();
204204
it++)
205205
{
206-
const typet &it_type=it->type();
206+
const typet it_type=it->type();
207207
mp_integer a=1;
208208

209209
const bool packed=it_type.get_bool(ID_C_packed) ||

0 commit comments

Comments
 (0)