Skip to content

Commit 56d6523

Browse files
committed
fix indexing error in Array.insert family
1 parent 4b940e5 commit 56d6523

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/container/array.onyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Array.insert :: (arr: &[..] $T, idx: u32, x: T) -> bool {
166166
if !Array.ensure_capacity(arr, arr.count + 1) do return false;
167167

168168
arr.count += 1;
169-
while i := arr.count; i > idx {
169+
while i := arr.count - 1; i > idx {
170170
arr.data[i] = arr.data[i - 1];
171171
i -= 1;
172172
}
@@ -181,7 +181,7 @@ Array.insert :: (arr: &[..] $T, idx: u32, new_arr: [] T) -> bool {
181181
if !Array.ensure_capacity(arr, arr.count + new_arr.count) do return false;
182182

183183
arr.count += new_arr.count;
184-
while i := arr.count; i > idx {
184+
while i := arr.count - 1; i > idx {
185185
arr.data[i] = arr.data[i - new_arr.count];
186186
i -= 1;
187187
}
@@ -198,7 +198,7 @@ Array.insert_empty :: (arr: &[..] $T, idx: u32) -> bool {
198198
if !Array.ensure_capacity(arr, arr.count + 1) do return false;
199199

200200
arr.count += 1;
201-
while i := arr.count; i > idx {
201+
while i := arr.count - 1; i > idx {
202202
arr.data[i] = arr.data[i - 1];
203203
i -= 1;
204204
}

0 commit comments

Comments
 (0)