GNOME Bugzilla – Bug 540730
Compiler accepts invalid array creation expressions for stacked arrays
Last modified: 2010-03-20 16:42:49 UTC
The code compiles, but running it causes a segfault.
Created attachment 113596 [details] Test case
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 ?
Sebastian, that's actually invalid code. The array in your test case is a stacked/jagged array, not a two-dimensional array. The example from Amos shows how a two-dimensional array should look like. I'm changing the bug summary to reflect the missing validation of the array creation expression.
Amos, that's a different issue, can you please open a separate bug for this?
commit cb808bc94d7e0c2045af52595d5d358b102ce32e Author: Jürg Billeter <j@bitron.ch> Date: Sat Mar 20 17:42:00 2010 +0100 Report error on invalid array creation expressions for stacked arrays Fixes bug 540730.