mirror of
https://github.com/ziglang/zig.git
synced 2025-12-28 17:13:19 +00:00
This adds a standalone test case to ensure the runtime does not trap when performing a memory.copy or memory.fill instruction while the destination or source address is out-of-bounds and the length is 0.
24 lines
529 B
Zig
24 lines
529 B
Zig
const std = @import("std");
|
|
|
|
test {
|
|
var dest = foo();
|
|
var source = foo();
|
|
|
|
@memcpy(dest, source);
|
|
@memset(dest, 4);
|
|
@memset(dest, undefined);
|
|
|
|
var dest2 = foo2();
|
|
@memset(dest2, 0);
|
|
}
|
|
|
|
fn foo() []u8 {
|
|
const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1);
|
|
return @as([*]align(1) u8, @ptrFromInt(ptr))[0..0];
|
|
}
|
|
|
|
fn foo2() []u64 {
|
|
const ptr = comptime std.mem.alignBackward(usize, std.math.maxInt(usize), 1);
|
|
return @as([*]align(1) u64, @ptrFromInt(ptr))[0..0];
|
|
}
|