From 903d06bab8ba6c5fd2e30fb29dfc327f304f1ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Wollenschl=C3=A4ger?= Date: Fri, 19 Jul 2019 23:46:47 +0900 Subject: [PATCH] Fix the range of destroyed elements when shrinking a seq (#11785) --- lib/core/seqs.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/seqs.nim b/lib/core/seqs.nim index bbbcf069ec..2892e4d8a5 100644 --- a/lib/core/seqs.nim +++ b/lib/core/seqs.nim @@ -138,7 +138,7 @@ proc shrink*[T](x: var seq[T]; newLen: Natural) = mixin `=destroy` sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'" when not supportsCopyMem(T): - for i in countdown(x.len - 1, newLen - 1): + for i in countdown(x.len - 1, newLen): `=destroy`(x[i]) # XXX This is wrong for const seqs that were moved into 'x'! cast[ptr NimSeqV2[T]](addr x).len = newLen