1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

array.slice(): bounds out of range check

This commit is contained in:
Alexander Medvednikov 2019-07-21 16:55:04 +02:00
parent ac238a5362
commit 4d5336897e

View File

@ -136,8 +136,11 @@ pub fn (s array) slice(start, _end int) array {
if start > end {
panic('invalid slice index: $start > $end')
}
if end >= s.len {
end = s.len
if end > s.len {
panic('runtime error: slice bounds out of range ($end >= $s.len)')
}
if start < 0 {
panic('runtime error: slice bounds out of range ($start < 0)')
}
l := end - start
res := array {