After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 544145 - Multidimensional array wrong code generation
Multidimensional array wrong code generation
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.3.x
Other All
: Normal normal
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-07-22 11:35 UTC by Amos Brocco
Modified: 2008-11-12 20:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch agains SVN 1719 (610 bytes, patch)
2008-07-22 11:37 UTC, Amos Brocco
rejected Details | Review
alternative patch (different semantic) (1.18 KB, patch)
2008-07-22 11:48 UTC, Amos Brocco
committed Details | Review

Description Amos Brocco 2008-07-22 11:35:48 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)
Comment 1 Amos Brocco 2008-07-22 11:37:42 UTC
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);
Comment 2 Amos Brocco 2008-07-22 11:48:52 UTC
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)
Comment 3 Jürg Billeter 2008-07-22 14:48:38 UTC
Thanks for the patches. The second one follows the right approach.
Comment 4 Jürg Billeter 2008-07-22 14:52:34 UTC
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.