]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Clear existing length values when revisiting a slice expression
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 5 Jan 2022 19:45:10 +0000 (20:45 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 8 Jan 2022 11:21:05 +0000 (12:21 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1274

codegen/valaccodearraymodule.vala
codegen/valaglibvalue.vala

index 117395d653924176d020f1c86d170dd6a865ef67..0a76c72cba4612f0452cbd410aeeb396d14eac61 100644 (file)
@@ -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) {
index ed095cf838e9bdb2bfbb60ade050a668ca980c4a..acd8ac9d7eaf6f82b806466d187ef8a21efc4569 100644 (file)
@@ -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<CCodeExpression>? get_array_lengths (Expression expr) {
                unowned GLibValue? glib_value = (GLibValue) expr.target_value;
                if (glib_value == null) {