Skip to content

Commit

Permalink
Revert the last two commits in this branch
Browse files Browse the repository at this point in the history
When the slice-by-length start position is runtime-known, it is likely
protected by a runtime-known condition and therefore a compile error is
less appropriate than a runtime panic check.

This is demonstrated in the json code that was updated and then reverted
in this commit.

When ziglang#3806 is implemented, this decision can be reassessed.

Revert "std: work around compiler unable to evaluate condition at compile time"
Revert "frontend: comptime array slice-by-length OOB detection"

This reverts commit 7741aca.
This reverts commit 2583b38.
  • Loading branch information
andrewrk committed Mar 21, 2024
1 parent 3990c8e commit d5cfbb4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions compile_errors/out of bounds array slice by length.zig

This file was deleted.

4 changes: 2 additions & 2 deletions safety/out of bounds array slice by length.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const std = @import("std");

pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = stack_trace;
if (std.mem.eql(u8, message, "index out of bounds: index 9, len 5")) {
if (std.mem.eql(u8, message, "index out of bounds: index 16, len 5")) {
std.process.exit(0);
}
std.process.exit(1);
}
pub fn main() !void {
var buf: [5]u8 = undefined;
_ = buf[foo(6)..][0..3];
_ = buf[foo(6)..][0..10];
return error.TestFailed;
}
fn foo(a: u32) u32 {
Expand Down

0 comments on commit d5cfbb4

Please sign in to comment.