From b7e999efaf38bce1f7e5527c77ccb75c37ac6643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Thu, 24 Oct 2019 08:06:19 +0200 Subject: [PATCH] Fix sequtils.delete bug with out of bounds indexes --- lib/pure/collections/sequtils.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 00bb0300d9bb..a16cf66a7855 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -434,7 +434,9 @@ proc delete*[T](s: var seq[T]; first, last: Natural) = var dest = @[1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1] dest.delete(3, 8) assert outcome == dest - + doAssert first <= last + if first >= s.len: + return var i = first var j = min(len(s), last+1) var newLen = len(s)-j+i @@ -1156,6 +1158,9 @@ when isMainModule: assert outcome == dest, """\ Deleting range 3-9 from [1,1,1,2,2,2,2,2,2,1,1,1,1,1] is [1,1,1,1,1,1,1,1]""" + var x = @[1, 2, 3] + x.delete(100, 100) + assert x == @[1, 2, 3] block: # insert tests var dest = @[1, 1, 1, 1, 1, 1, 1, 1]