From 427ef81a86c3857bc86276dd35c12084ee065ee9 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sat, 2 Sep 2017 09:46:33 +0200 Subject: [PATCH] codegen: Initialize temp-variable for fixed-size arrays to zero first https://bugzilla.gnome.org/show_bug.cgi?id=787152 --- codegen/valaccodearraymodule.vala | 1 + tests/Makefile.am | 1 + tests/basic-types/bug787152.vala | 8 ++++++++ 3 files changed, 10 insertions(+) create mode 100644 tests/basic-types/bug787152.vala diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index 2b78bbc7d..ea0a85ded 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -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; diff --git a/tests/Makefile.am b/tests/Makefile.am index 16724e3aa..ab30d62f2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,6 +45,7 @@ TESTS = \ basic-types/bug761736.vala \ basic-types/bug771626.test \ 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 index 000000000..a6ae36b85 --- /dev/null +++ b/tests/basic-types/bug787152.vala @@ -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); +} -- 2.47.3