[vala] codegen: Guard pointer indirection of lengths when returning arrays



commit 735ffbf261757820cb320944ced62616aff0a2d0
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue May 24 23:47:45 2011 +0200

    codegen: Guard pointer indirection of lengths when returning arrays
    
    Fixes bug 638415.

 codegen/valaccodebasemodule.vala |    2 ++
 tests/Makefile.am                |    1 +
 tests/delegates/bug638415.vala   |   12 ++++++++++++
 3 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1277cd1..b4efc50 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3191,11 +3191,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				var len_l = get_result_cexpression (get_array_length_cname ("result", dim));
+				ccode.open_if (len_l);
 				if (!is_in_coroutine ()) {
 					len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, len_l);
 				}
 				var len_r = get_array_length_cexpression (stmt.return_expression, dim);
 				ccode.add_assignment (len_l, len_r);
+				ccode.close ();
 			}
 
 			set_cvalue (stmt.return_expression, get_variable_cexpression (return_expr_decl.name));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f8fec7..013585e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ TESTS = \
 	delegates/delegates.vala \
 	delegates/bug595610.vala \
 	delegates/bug595639.vala \
+	delegates/bug638415.vala \
 	delegates/bug639751.vala \
 	objects/classes.vala \
 	objects/fields.vala \
diff --git a/tests/delegates/bug638415.vala b/tests/delegates/bug638415.vala
new file mode 100644
index 0000000..2e98842
--- /dev/null
+++ b/tests/delegates/bug638415.vala
@@ -0,0 +1,12 @@
+[CCode (array_length = false)]
+public delegate string[] Deleg ();
+
+string[] foo () {
+	return new string[0];
+}
+
+void main () {
+	Deleg bar = foo;
+	bar ();
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]