From 2adfbfc8307ed00be4a3f2d4c8dd22f69998a0ba Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 24 May 2020 11:10:41 +0300 Subject: [PATCH] builtin: fix a bug in array_delete --- vlib/builtin/array.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 4f77dce481..7c300eb68c 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -148,7 +148,9 @@ pub fn (mut a array) delete(i int) { } } size := a.element_size - C.memmove(byteptr(a.data) + i * size, byteptr(a.data) + (i + 1) * size, (a.len - i) * size) + // NB: if a is [12,34], a.len = 2, a.delete(0) + // should move (2-0-1) elements = 1 element (the 34) forward + C.memmove(byteptr(a.data) + i * size, byteptr(a.data) + (i + 1) * size, (a.len - i - 1) * size) a.len-- }