]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Initialize temp-variable for fixed-size arrays to zero first
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 2 Sep 2017 07:46:33 +0000 (09:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 2 Sep 2017 15:40:54 +0000 (17:40 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=787152

codegen/valaccodearraymodule.vala
tests/Makefile.am
tests/basic-types/bug787152.vala [new file with mode: 0644]

index 2b78bbc7d483615e98c21cf206b85d30d7a3cf04..ea0a85ded308bda4062cc1d236d26e850da5608b 100644 (file)
@@ -44,6 +44,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        // no heap allocation for fixed-length arrays
 
                        var temp_var = get_temp_variable (array_type, true, expr);
+                       temp_var.init = true;
                        var name_cnode = get_variable_cexpression (temp_var.name);
                        int i = 0;
 
index 48c0cb0eb9546747e24ec4801f9a025adde1195e..b3e5f7cc85cdfcb14c2f6a4c0f9a99a3ea0c915f 100644 (file)
@@ -47,6 +47,7 @@ TESTS = \
        basic-types/bug771626.test \
        basic-types/bug772426.vala \
        basic-types/bug777697.test \
+       basic-types/bug787152.vala \
        chainup/class-base.vala \
        chainup/class-base-foo.vala \
        chainup/class-object.vala \
diff --git a/tests/basic-types/bug787152.vala b/tests/basic-types/bug787152.vala
new file mode 100644 (file)
index 0000000..a6ae36b
--- /dev/null
@@ -0,0 +1,8 @@
+void main () {
+       int test[6] = { 23, 4711, 42 };
+       assert (test[4] == 0);
+       assert (test[5] == 0);
+       int test2[6] = test;
+       assert (test2[4] == 0);
+       assert (test2[5] == 0);
+}