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

Slice operations slice_sentinel and slice_length (with sentinel) produce runtime safety checks testing incorrect (underestimated) upper bounds #19794

Open
amp-59 opened this issue Apr 28, 2024 · 0 comments · May be fixed by #19764

Comments

@amp-59
Copy link
Contributor

amp-59 commented Apr 28, 2024

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behaviour

Compile and run example program with zig run underestimate_upper_bound.zig
underestimate_upper_bound.zig:

var dest_end: usize = 3;
pub fn main() void {
    const src_mem: [3:0]usize = .{ 0, 0, 0 };
    const src_ptr: [:0]const usize = &src_mem;
    _ = src_ptr[0..dest_end :0];
    _ = src_ptr[0..][0..dest_end :0];
}

Output:

zig run underestimate_upper_bound.zig
thread 96316 panic: index out of bounds: index 4, len 3
./underestimate_upper_bound.zig:5:16: 0x1033e49 in main (underestimate_upper_bound)
    _ = src_ptr[0..dest_end :0];
               ^
~/.local/src/zig-linux-x86_64-0.13.0-dev.46+3648d7df1/lib/std/start.zig:501:22: 0x1033669 in posixCallMainAndExit (underestimate_upper_bound)
            root.main();
                     ^
~/.local/src/zig-linux-x86_64-0.13.0-dev.46+3648d7df1/lib/std/start.zig:253:5: 0x10331d1 in _start (underestimate_upper_bound)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)

Expected Behaviour

The panic condition should match the compile error condition.

@amp-59 amp-59 linked a pull request Apr 28, 2024 that will close this issue
40 tasks
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

Successfully merging a pull request may close this issue.

1 participant