From: Jean Privat Date: Wed, 2 Dec 2015 18:22:42 +0000 (-0500) Subject: core/array: fix implementation of naive copy_to to avoid overwriting X-Git-Tag: v0.8~59^2~3 X-Git-Url: http://nitlanguage.org core/array: fix implementation of naive copy_to to avoid overwriting Signed-off-by: Jean Privat --- diff --git a/lib/core/collection/array.nit b/lib/core/collection/array.nit index 0896bab..e8f57c0 100644 --- a/lib/core/collection/array.nit +++ b/lib/core/collection/array.nit @@ -112,10 +112,18 @@ abstract class AbstractArrayRead[E] fun copy_to(start: Int, len: Int, dest: AbstractArray[E], new_start: Int) do # TODO native one - var i = len - while i > 0 do - i -= 1 - dest[new_start+i] = self[start+i] + if start < new_start then + var i = len + while i > 0 do + i -= 1 + dest[new_start+i] = self[start+i] + end + else + var i = 0 + while i < len do + dest[new_start+i] = self[start+i] + i += 1 + end end end