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 686601 - codegen: handle negative array index for slice
codegen: handle negative array index for slice
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2012-10-22 02:21 UTC by Daiki Ueno
Modified: 2018-05-22 14:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: handle negative array index for slice (2.76 KB, patch)
2012-10-22 02:21 UTC, Daiki Ueno
none Details | Review
codegen: handle negative array index for slice (3.67 KB, patch)
2012-10-22 09:01 UTC, Daiki Ueno
none Details | Review

Description Daiki Ueno 2012-10-22 02:21:27 UTC
While string.slice() accepts negative indices, array's doesn't.  This is another pitfall which I often fall into and causes out-of-range access.

How about supporting the negative indices even in array slice?
Comment 1 Daiki Ueno 2012-10-22 02:21:29 UTC
Created attachment 226953 [details] [review]
codegen: handle negative array index for slice
Comment 2 Daiki Ueno 2012-10-22 09:01:59 UTC
Created attachment 226974 [details] [review]
codegen: handle negative array index for slice

Factored out index conversion and added range check assertions.
Comment 3 Jürg Billeter 2012-11-12 06:30:51 UTC
Thanks for the patch. My concern is that this is not always expected and may break existing code. At least when working with pointers, negative array indexes may be used to access data below the pointer address.

Even if we say we ignore pointers for now, there are cases where this change will hide bugs. If an array index is calculated and it ends up as a negative number, I'd like to see an out of bounds error. Right now I may need valgrind to detect this, however, out of bounds detection may be added to Vala itself one day. If we apply this change, this will no longer be possible.
Comment 4 GNOME Infrastructure Team 2018-05-22 14:32:39 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/328.