GNOME Bugzilla – Bug 544145
Multidimensional array wrong code generation
Last modified: 2008-11-12 20:48:13 UTC
(from http://bugzilla.gnome.org/show_bug.cgi?id=540730#c2) The following code: MyClass[,] matrix2o = new MyClass[10,10]; Produces the following: _tmp6 = NULL; matrix2o = (_tmp6 = g_new0 (MyClass*, 10 + 1 * 10 + 1), matrix2o_length1 = 10, matrix2o_length2 = 10, _tmp6); In fact, because of missing brackets, the allocated size of just 21 instead of 10*10 = 100. Also, I don't understand the + 1, shouldn't MyClass[10,10] define an array of 100 elements ? ok... "add extra item to have array NULL-terminated for all reference types" (from valaccodearraycreationexpressionbinding.vala)
Created attachment 114996 [details] [review] Patch agains SVN 1719 This patch fixes the bug (adds missing parenthesis), so that: MyClass[,] matrix2o = new MyClass[10,10]; generates: matrix2o = (_tmp6 = g_new0 (MyClass*, (10 + 1) * (10 + 1)), matrix2o_length1 = 10, matrix2o_length2 = 10, _tmp6);
Created attachment 114998 [details] [review] alternative patch (different semantic) as I'm not sure how the final null is used (I've yet to dig a little bit more in the code), here's an alternative patch that for: MyClass[,] matrix2o = new MyClass[10,10]; generates: matrix2o = (_tmp6 = g_new0 (MyClass*, 10 * 10 + 1), matrix2o_length1 = 10, matrix2o_length2 = 10, _tmp6); (i.e. only one null at the end)
Thanks for the patches. The second one follows the right approach.
2008-07-22 Jürg Billeter <j@bitron.ch> * gobject/valaccodearraycreationexpressionbinding.vala: Fix crash when using multi-dimensional arrays, patch by Amos Brocco, fixes bug 544145 Fixed in r1721.