Fix the range of destroyed elements when shrinking a seq (#11785)

This commit is contained in:
Jörg Wollenschläger
2019-07-19 23:46:47 +09:00
committed by Andreas Rumpf
parent a5d6080a81
commit 903d06bab8

View File

@@ -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