From 4d5336897ef17e6934d9d8b873bc639f8d08a922 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 21 Jul 2019 16:55:04 +0200 Subject: [PATCH] array.slice(): bounds out of range check --- vlib/builtin/array.v | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 5fab9eef0c..78591e8852 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -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 {