From 6cfa112524d13f878d02149475079e34cd366116 Mon Sep 17 00:00:00 2001 From: Jeremy Philippe Date: Wed, 8 Jan 2020 13:20:31 +0100 Subject: vala: Non-nullable value-type in coalesce expression needs to be copied The code generated by the coalesce expression could lead to stale pointers to the stack if the right-side expression is an immediate value (such as an integer literal or a struct). Fixes https://gitlab.gnome.org/GNOME/vala/issues/893 --- vala/valabinaryexpression.vala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'vala/valabinaryexpression.vala') diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index fe559e1d5..927ca5413 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -234,6 +234,12 @@ public class Vala.BinaryExpression : Expression { local_type = right.value_type.copy (); } + if (local_type != null && right.value_type is ValueType && !right.value_type.nullable) { + // immediate values in the right expression must always be boxed, + // otherwise the local variable may receive a stale pointer to the stack + local_type.value_owned = true; + } + var local = new LocalVariable (local_type, get_temp_name (), left, source_reference); var decl = new DeclarationStatement (local, source_reference); -- cgit v1.2.1