array.slice(): bounds out of range check

pull/1260/head
Alexander Medvednikov 2019-07-21 16:55:04 +02:00
parent ac238a5362
commit 4d5336897e
1 changed files with 5 additions and 2 deletions

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 {