Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.insert writes outside bounds of array #179

Closed
dgriffie79 opened this issue Dec 24, 2024 · 1 comment
Closed

Array.insert writes outside bounds of array #179

dgriffie79 opened this issue Dec 24, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@dgriffie79
Copy link
Contributor

dgriffie79 commented Dec 24, 2024

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 ]

@brendanfh brendanfh added the bug Something isn't working label Dec 26, 2024
@brendanfh brendanfh self-assigned this Dec 26, 2024
@dgriffie79
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants