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 639441 - ElementAccess should check for valid rank access (always) and for index access in fixed-size and constant arrays
ElementAccess should check for valid rank access (always) and for index acces...
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.11.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-13 16:23 UTC by Marco Trevisan (Treviño)
Modified: 2018-02-17 20:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
ElementAccess check for valid rank and index access in fixed-size and constant arrays (3.88 KB, patch)
2011-01-13 16:23 UTC, Marco Trevisan (Treviño)
none Details | Review

Description Marco Trevisan (Treviño) 2011-01-13 16:23:57 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.
Comment 1 Rico Tzschichholz 2018-02-17 20:15:43 UTC
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