From feb1108807f72b17a57b3665188e7312a07c7827 Mon Sep 17 00:00:00 2001 From: reuk Date: Sun, 16 Apr 2017 23:12:43 +0100 Subject: [PATCH] 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. --- src/ansi-c/padding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansi-c/padding.cpp b/src/ansi-c/padding.cpp index cdcc1cd802b..16391ee33a7 100644 --- a/src/ansi-c/padding.cpp +++ b/src/ansi-c/padding.cpp @@ -203,7 +203,7 @@ void add_padding(struct_typet &type, const namespacet &ns) it!=components.end(); it++) { - const typet &it_type=it->type(); + const typet it_type=it->type(); mp_integer a=1; const bool packed=it_type.get_bool(ID_C_packed) ||