You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Array.insert functions will copy the last element of the array to outside the bounds of the array when the new array.count = array.capacity. The loop that moves the elements indexes from array[new_count] instead of array[new_count - 1].
use core {*}
main :: () {
foo := Array.make(u32)
// fill array
foo->push(0)
foo->push(1)
foo->push(3)
foo->push(4)
//remove last element and insert
foo->pop()
foo->insert(2, 2)
//element has been written outside bounds of array
printf("Capacity: {}, Count: {}, Values: {}\n", foo.capacity, foo.count, foo[0..5])
}
ouputs:
Capacity: 4, Count: 4, Values: [ 0, 1, 2, 3, 4 ]
The text was updated successfully, but these errors were encountered:
Hello, this issue still affects the other two flavors of array.insert (insert multiple elements, insert a zeroed element). I should have mentioned I submitted a PR for all 3 of these.
Array.insert functions will copy the last element of the array to outside the bounds of the array when the new array.count = array.capacity. The loop that moves the elements indexes from array[new_count] instead of array[new_count - 1].
ouputs:
Capacity: 4, Count: 4, Values: [ 0, 1, 2, 3, 4 ]
The text was updated successfully, but these errors were encountered: