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

inject_at writes out of bounds when given a negative index argument #4595

Open
jace0x21 opened this issue Dec 18, 2024 · 1 comment
Open

Comments

@jace0x21
Copy link

Context

The following program writes out of bounds. Is this expected behavior? An assert could be added to the inject_at family of procedures but I see that there is a pop and pop_safe which leads me to believe an assert isn't the favored approach.

package main

import "core:fmt"

main :: proc() {
    test: [dynamic]int

    inject_at(&test, 0, 50)
    fmt.printf("%v\n", test)
    
    inject_at(&test, 1, 100)
    fmt.printf("%v\n", test)
    
    inject_at(&test, -1, 150)
    fmt.printf("%v\n", test)
}
  • Operating System & Odin Version:
    Odin: dev-2024-12:0a29d36aa
    OS: macOS Sonoma 14.4.1 (build 23E224, kernel 23.4.0)
    CPU: Apple M2
    RAM: 24576 MiB
    Backend: LLVM 18.1.8

Expected Behavior

I expected inject_at to not write out of bounds and return false or panic at runtime.

Current Behavior

inject_at will write out of bounds given a negative index

Steps to Reproduce

  1. Write the above example to a file
  2. odin run example.odin -file

Failure Logs

On my machine, the output is:
[50]
[50, 100]
[105553138418384, 50, 100]

@jace0x21
Copy link
Author

Btw, if there is a clear alternative approach that we want to take here, I'd be happy to assist in implementation. But again unsure if this is just expected or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant