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

When Accessing a Slice in an rodata struct, it can still be modified #3965

Closed
kranasAngel opened this issue Jul 23, 2024 · 1 comment
Closed

Comments

@kranasAngel
Copy link

kranasAngel commented Jul 23, 2024

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

related to the resolved: #3964

  • Operating System & Odin Version:
    macos sonoma | dev-2024-07:bc5b41938

Expected Behavior

Expecting a bus error like when trying to modify a readonly array in a struct

Current Behavior

What is the current behavior? the slice is modified successfully

Steps to Reproduce

MyStruct :: struct { nums : []int, arr_nums : [3]int}

@(rodata)
my_struct : MyStruct = MyStruct{nums = []int {1,2,3}, arr_nums = [3]int {4,5,6}}

ret_m_slice :: proc() -> MyStruct {
    return my_struct;
}

main :: proc() {
    x := ret_m_slice();
    fmt.println(x);
    fmt.println("modify slice local");
    x.nums[1] = 11;
    fmt.println(ret_m_slice());
    fmt.println("modify slice direct");
    my_struct.nums[1] = 99;
    fmt.println(ret_m_slice());
    //throws error                                                                                                                                                     
    fmt.println("modify arr");
    my_struct.arr_nums[1] = 22;
    fmt.println(ret_m_slice());
    
}

Failure Logs

odin build temp && ./temp.bin                                                                                                  
MyStruct{nums = [1, 2, 3], arr_nums = [4, 5, 6]}                                                                                                                       
modify slice local                                                                                                                                                     
MyStruct{nums = [1, 11, 3], arr_nums = [4, 5, 6]}                                                                                                                      
modify slice direct                                                                                                                                                    
MyStruct{nums = [1, 99, 3], arr_nums = [4, 5, 6]}                                                                                                                      
modify arr                                                                                                                                                             
zsh: bus error  ./temp.bin
@kranasAngel
Copy link
Author

Fixed by b0fe777

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