From 537f9052167a683c922c9815eb9fdce5b0778dc2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 12 May 2022 21:10:01 -0700 Subject: [PATCH] fix bad runtime safety test cases The "slicing operator with sentinel" runtime safety test cases should all have been compile errors in their current forms. In this commit I adjust them to use runtime-known slices before triggering the runtime safety. Furthermore the test cases did not actually have unique names. --- test/runtime_safety.zig | 56 +++++------------------------------------ 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig index 0a1e7e00f3..f73226159a 100644 --- a/test/runtime_safety.zig +++ b/test/runtime_safety.zig @@ -95,67 +95,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\} ; - cases.addRuntimeSafety("slicing operator with sentinel", + cases.addRuntimeSafety("slice with sentinel out of bounds", \\const std = @import("std"); ++ check_panic_msg ++ \\pub fn main() void { \\ var buf = [4]u8{'a','b','c',0}; - \\ const slice = buf[0..4 :0]; + \\ const input: []u8 = &buf; + \\ const slice = input[0..4 :0]; \\ _ = slice; \\} ); - cases.addRuntimeSafety("slicing operator with sentinel", - \\const std = @import("std"); - ++ check_panic_msg ++ - \\pub fn main() void { - \\ var buf = [4]u8{'a','b','c',0}; - \\ const slice = buf[0..:0]; - \\ _ = slice; - \\} - ); - cases.addRuntimeSafety("slicing operator with sentinel", + cases.addRuntimeSafety("empty slice with sentinel out of bounds", \\const std = @import("std"); ++ check_panic_msg ++ \\pub fn main() void { \\ var buf_zero = [0]u8{}; - \\ const slice = buf_zero[0..0 :0]; - \\ _ = slice; - \\} - ); - cases.addRuntimeSafety("slicing operator with sentinel", - \\const std = @import("std"); - ++ check_panic_msg ++ - \\pub fn main() void { - \\ var buf_zero = [0]u8{}; - \\ const slice = buf_zero[0..:0]; - \\ _ = slice; - \\} - ); - cases.addRuntimeSafety("slicing operator with sentinel", - \\const std = @import("std"); - ++ check_panic_msg ++ - \\pub fn main() void { - \\ var buf_sentinel = [2:0]u8{'a','b'}; - \\ @ptrCast(*[3]u8, &buf_sentinel)[2] = 0; - \\ const slice = buf_sentinel[0..3 :0]; - \\ _ = slice; - \\} - ); - cases.addRuntimeSafety("slicing operator with sentinel", - \\const std = @import("std"); - ++ check_panic_msg ++ - \\pub fn main() void { - \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; - \\ const slice = buf_slice[0..3 :0]; - \\ _ = slice; - \\} - ); - cases.addRuntimeSafety("slicing operator with sentinel", - \\const std = @import("std"); - ++ check_panic_msg ++ - \\pub fn main() void { - \\ var buf_slice: []const u8 = &[3]u8{ 'a', 'b', 0 }; - \\ const slice = buf_slice[0.. :0]; + \\ const input: []u8 = &buf_zero; + \\ const slice = input[0..0 :0]; \\ _ = slice; \\} );