aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-20 18:19:01 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-12-20 18:28:59 -0500
commit8d73703d524e06e17320e025ff970c86ebc01d22 (patch)
tree1c9eae2163aa25df4380c6b6690933f5cec62ca1 /test
parent8918cb06fca10309dc67ac881894528eac33a8fc (diff)
downloadzig-8d73703d524e06e17320e025ff970c86ebc01d22.tar.gz
zig-8d73703d524e06e17320e025ff970c86ebc01d22.zip
fix safety for sentinel-slicing floats
Diffstat (limited to 'test')
-rw-r--r--test/runtime_safety.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig
index 6a1cc808fd..2217a7f2df 100644
--- a/test/runtime_safety.zig
+++ b/test/runtime_safety.zig
@@ -1,6 +1,34 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompareOutputContext) void {
+ cases.addRuntimeSafety("slice sentinel mismatch - optional pointers",
+ \\const std = @import("std");
+ \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
+ \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
+ \\ std.process.exit(126); // good
+ \\ }
+ \\ std.process.exit(0); // test failed
+ \\}
+ \\pub fn main() void {
+ \\ var buf: [4]?*i32 = undefined;
+ \\ const slice = buf[0..3 :null];
+ \\}
+ );
+
+ cases.addRuntimeSafety("slice sentinel mismatch - floats",
+ \\const std = @import("std");
+ \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
+ \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
+ \\ std.process.exit(126); // good
+ \\ }
+ \\ std.process.exit(0); // test failed
+ \\}
+ \\pub fn main() void {
+ \\ var buf: [4]f32 = undefined;
+ \\ const slice = buf[0..3 :1.2];
+ \\}
+ );
+
cases.addRuntimeSafety("pointer slice sentinel mismatch",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {