]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Keep arrays NULL-terminated when appending
authorJürg Billeter <j@bitron.ch>
Thu, 12 Feb 2009 11:39:03 +0000 (11:39 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 12 Feb 2009 11:39:03 +0000 (11:39 +0000)
2009-02-12  Jürg Billeter  <j@bitron.ch>

* gobject/valaccodearraymodule.vala:

Keep arrays NULL-terminated when appending

svn path=/trunk/; revision=2431

ChangeLog
gobject/valaccodearraymodule.vala

index 94b3d3967059a30d7a087829e246cbec6ea13db8..196a87dcb497c77d04376c6bb6846f2aac2044e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-02-12  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodearraymodule.vala:
+
+       Keep arrays NULL-terminated when appending
+
 2009-02-11  Ryan Lortie  <desrt@desrt.ca>
 
        Bug 571263 – make yielding functions dispatch results to mainloop
index db25121436c12976be6c242809021c1fdd7de47f..0b6bf0ee4f542e0ebc9d9162875f649772d5e387 100644 (file)
@@ -601,7 +601,12 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew"));
                renew_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
                renew_call.add_argument (array);
-               renew_call.add_argument (size);
+               if (array_type.element_type.is_reference_type_or_type_parameter ()) {
+                       // NULL terminate array
+                       renew_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, size, new CCodeConstant ("1")));
+               } else {
+                       renew_call.add_argument (size);
+               }
 
                var resize_block = new CCodeBlock ();
                resize_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (size, new CCodeConditionalExpression (size, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("2"), size), new CCodeConstant ("4")))));
@@ -612,6 +617,11 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (array, new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, length)), value)));
 
+               if (array_type.element_type.is_reference_type_or_type_parameter ()) {
+                       // NULL terminate array
+                       block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (array, length), new CCodeConstant ("NULL"))));
+               }
+
                // append to file
 
                source_type_member_declaration.append (function.copy ());