GNOME Bugzilla – Bug 686601
codegen: handle negative array index for slice
Last modified: 2018-05-22 14:32:39 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?
Created attachment 226953 [details] [review] codegen: handle negative array index for slice
Created attachment 226974 [details] [review] codegen: handle negative array index for slice Factored out index conversion and added range check assertions.
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.
-- 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.