From: Juerg Billeter Date: Sat, 26 Apr 2008 14:30:01 +0000 (+0000) Subject: Always initialize local array length variables, fixes bug 529863 X-Git-Tag: VALA_0_3_2~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5477b7115d3bc03339bc714b92cb04dbd4c02deb;p=thirdparty%2Fvala.git Always initialize local array length variables, fixes bug 529863 2008-04-26 Juerg Billeter * gobject/valaccodegenerator.vala: Always initialize local array length variables, fixes bug 529863 svn path=/trunk/; revision=1323 --- diff --git a/ChangeLog b/ChangeLog index 2214f0d79..e4bc96ac7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-04-26 Jürg Billeter + + * gobject/valaccodegenerator.vala: + + Always initialize local array length variables, fixes bug 529863 + 2008-04-26 Jürg Billeter * vala/valaarraytype.vala: diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 3bdd632b0..bed640a06 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -1180,8 +1180,23 @@ public class Vala.CCodeGenerator : CodeGenerator { rhs = ccomma; } } - } else if (local.variable_type.data_type != null && local.variable_type.data_type.is_reference_type ()) { + } else if (local.variable_type.is_reference_type_or_type_parameter ()) { rhs = new CCodeConstant ("NULL"); + + if (local.variable_type is ArrayType) { + // initialize array length variables + var array_type = (ArrayType) local.variable_type; + + var ccomma = new CCodeCommaExpression (); + + for (int dim = 1; dim <= array_type.rank; dim++) { + ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (get_array_length_cname (local.name, dim)), new CCodeConstant ("0"))); + } + + ccomma.append_expression (rhs); + + rhs = ccomma; + } } var cvar = new CCodeVariableDeclarator.with_initializer (get_variable_cname (local.name), rhs); @@ -1196,7 +1211,7 @@ public class Vala.CCodeGenerator : CodeGenerator { } /* try to initialize uninitialized variables */ - if (local.initializer == null) { + if (cvar.initializer == null) { cvar.initializer = default_value_for_type (local.variable_type, true); }