From: Jürg Billeter Date: Thu, 12 Feb 2009 11:39:03 +0000 (+0000) Subject: Keep arrays NULL-terminated when appending X-Git-Tag: 0.5.7~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffa685e2627b186db227e3e1042473a20ec8e976;p=thirdparty%2Fvala.git Keep arrays NULL-terminated when appending 2009-02-12 Jürg Billeter * gobject/valaccodearraymodule.vala: Keep arrays NULL-terminated when appending svn path=/trunk/; revision=2431 --- diff --git a/ChangeLog b/ChangeLog index 94b3d3967..196a87dcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-02-12 Jürg Billeter + + * gobject/valaccodearraymodule.vala: + + Keep arrays NULL-terminated when appending + 2009-02-11 Ryan Lortie Bug 571263 – make yielding functions dispatch results to mainloop diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala index db2512143..0b6bf0ee4 100644 --- a/gobject/valaccodearraymodule.vala +++ b/gobject/valaccodearraymodule.vala @@ -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 ());