From: Rico Tzschichholz Date: Wed, 5 Jan 2022 19:45:10 +0000 (+0100) Subject: codegen: Clear existing length values when revisiting a slice expression X-Git-Tag: 0.54.6~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f98c094c0fcbf1b8a09d6faf3b93e78026304e4a;p=thirdparty%2Fvala.git codegen: Clear existing length values when revisiting a slice expression Fixes https://gitlab.gnome.org/GNOME/vala/issues/1274 --- diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index b2707ff8d..632b26046 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -210,7 +210,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { var splicelen = new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, cstop, cstart); set_cvalue (expr, cstartpointer); - append_array_length (expr, splicelen); + // Make sure no previous length values are preserved + set_array_length (expr, splicelen); } void append_struct_array_free_loop (Struct st) { diff --git a/codegen/valaglibvalue.vala b/codegen/valaglibvalue.vala index ed095cf83..acd8ac9d7 100644 --- a/codegen/valaglibvalue.vala +++ b/codegen/valaglibvalue.vala @@ -142,6 +142,17 @@ namespace Vala { glib_value.append_array_length_cvalue (size); } + public static void set_array_length (Expression expr, CCodeExpression size) { + unowned GLibValue? glib_value = (GLibValue) expr.target_value; + if (glib_value == null) { + expr.target_value = new GLibValue (expr.value_type); + glib_value = (GLibValue) expr.target_value; + } else { + glib_value.array_length_cvalues = null; + } + glib_value.append_array_length_cvalue (size); + } + public static unowned List? get_array_lengths (Expression expr) { unowned GLibValue? glib_value = (GLibValue) expr.target_value; if (glib_value == null) {