Always initialize local array length variables, fixes bug 529863
authorJuerg Billeter <j@bitron.ch>
Sat, 26 Apr 2008 14:30:01 +0000 (14:30 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 26 Apr 2008 14:30:01 +0000 (14:30 +0000)
2008-04-26  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala:

Always initialize local array length variables, fixes bug 529863

svn path=/trunk/; revision=1323

ChangeLog
gobject/valaccodegenerator.vala

index 2214f0d..e4bc96a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-04-26  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegenerator.vala:
+
+       Always initialize local array length variables, fixes bug 529863
+
+2008-04-26  Jürg Billeter  <j@bitron.ch>
+
        * vala/valaarraytype.vala:
        * vala/valaclassinstancetype.vala:
        * vala/valaclasstype.vala:
index 3bdd632..bed640a 100644 (file)
@@ -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);
                }