| ... | @@ -1,6 +1,34 @@ | ... | @@ -1,6 +1,34 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | | 2 | |
| 3 | pub fn addCases(cases: *tests.CompareOutputContext) void { | 3 | pub fn addCases(cases: *tests.CompareOutputContext) void { |
| | 4 | cases.addRuntimeSafety("slice sentinel mismatch - optional pointers", |
| | 5 | \\const std = @import("std"); |
| | 6 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { |
| | 7 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| | 8 | \\ std.process.exit(126); // good |
| | 9 | \\ } |
| | 10 | \\ std.process.exit(0); // test failed |
| | 11 | \\} |
| | 12 | \\pub fn main() void { |
| | 13 | \\ var buf: [4]?*i32 = undefined; |
| | 14 | \\ const slice = buf[0..3 :null]; |
| | 15 | \\} |
| | 16 | ); |
| | 17 | |
| | 18 | cases.addRuntimeSafety("slice sentinel mismatch - floats", |
| | 19 | \\const std = @import("std"); |
| | 20 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { |
| | 21 | \\ if (std.mem.eql(u8, message, "sentinel mismatch")) { |
| | 22 | \\ std.process.exit(126); // good |
| | 23 | \\ } |
| | 24 | \\ std.process.exit(0); // test failed |
| | 25 | \\} |
| | 26 | \\pub fn main() void { |
| | 27 | \\ var buf: [4]f32 = undefined; |
| | 28 | \\ const slice = buf[0..3 :1.2]; |
| | 29 | \\} |
| | 30 | ); |
| | 31 | |
| 4 | cases.addRuntimeSafety("pointer slice sentinel mismatch", | 32 | cases.addRuntimeSafety("pointer slice sentinel mismatch", |
| 5 | \\const std = @import("std"); | 33 | \\const std = @import("std"); |
| 6 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { | 34 | \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn { |