GNOME Bugzilla – Bug 639441
ElementAccess should check for valid rank access (always) and for index access in fixed-size and constant arrays
Last modified: 2018-02-17 20:15:43 UTC
Created attachment 178243 [details] [review] ElementAccess check for valid rank and index access in fixed-size and constant arrays ElementAccess check for valid rank and index access in fixed-size and constant arrays Check if we are corrently accessing to a valid rank of an array. For example, when you have: int[,] array = {{1,2}, {3,4}}; You can't do: int i = array[0,1,0]; but vala syntax checker allowed this before, and vala compiler didn't work just due a codegen error (it wasn't possible to get the length parameter for the rank 2): ERROR:valaccodearraymodule.c:942:vala_ccode_array_module_real_get_array_length_cvalue: assertion failed: (_tmp20_) So, I've fixed the issue, checking for valid rank access for every array access (since rank is always known). Then, in constant arrays and in fixed_length arrays the max item (for each rank) you can access to is known too, so in the cases where the index is clearly specified (using an integer literal value), I've added a check to verify if that value fits in the array range for each array rank. For example if you have: int[,] array = {{1,2}, {3,4}}; Is a non sense doing: int i = array[1,5]; Vala didn't checked this before, now it does.
commit f9a5c8ed60ed319bcc79285fd137cd0d2f449cb6 Author: Luca Bruno <lucabru@src.gnome.org> Date: Sun Jul 24 09:53:55 2011 +0200 Report an error on element access with wrong number of indices