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 operation omits sentinel runtime safety check #19792

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

Slice operation omits sentinel runtime safety check #19792

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 omit_sentinel_safety_check.zig
omit_sentinel_safety_check.zig:

var src_mem: [3:0]u8 = .{ 'a', 'b', 'c' };
pub fn main() void {
    const src_ptr: [:0]const u8 = &src_mem;
    const slice: [:0]const u8 = src_ptr[0..1 :0];
    if (slice[slice.len] != 0) {
        unreachable;
    }
}

Output:

zig run omit_sentinel_safety_check.zig
thread 78585 panic: reached unreachable code
./omit_sentinel_safety_check.zig:6:9: 0x1033c18 in main (omit_sentinel_safety_check)
        unreachable;
        ^
~/.local/src/zig-linux-x86_64-0.13.0-dev.46+3648d7df1/lib/std/start.zig:501:22: 0x1033469 in posixCallMainAndExit (omit_sentinel_safety_check)
            root.main();
                     ^
~/.local/src/zig-linux-x86_64-0.13.0-dev.46+3648d7df1/lib/std/start.zig:253:5: 0x1032fd1 in _start (omit_sentinel_safety_check)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)

Expected Behaviour

The program should panic with sentinel_mismatch.

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