]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
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 2214f0d7902709dcbdfb966290f04b7d13442c40..e4bc96ac7fb2110b37610f0aed8dfc9681d6f94d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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:
index 3bdd632b0419507f27a1aec1dfd3a8e7160d2bd8..bed640a06ad77359fbc11b7704953bd0f7b27875 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);
                }