commit 8d914ea7340c920c1929c5d666fc802b15f49a64 (tree)
parent 1d8857bbe3d0fe2bb33c459b3f11209bab424882
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 10 Feb 2025 16:13:35 -0800
compiler_rt memcpy: avoid infinite recursion
when compiled in debug mode (--debug-rt)
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig
@@ -175,10 +175,11 @@ inline fn copyRange4(
const last = len - copy_len;
const pen = last - b;
- dest[0..copy_len].* = src[0..copy_len].*;
- dest[b..][0..copy_len].* = src[b..][0..copy_len].*;
- dest[pen..][0..copy_len].* = src[pen..][0..copy_len].*;
- dest[last..][0..copy_len].* = src[last..][0..copy_len].*;
+ const Int = @Type(.{ .int = .{ .signedness = .unsigned, .bits = copy_len * 8 } });
+ @as(*align(1) Int, @ptrCast(dest[0..copy_len])).* = @as(*align(1) const Int, @ptrCast(src[0..copy_len])).*;
+ @as(*align(1) Int, @ptrCast(dest[b..][0..copy_len])).* = @as(*align(1) const Int, @ptrCast(src[b..][0..copy_len])).*;
+ @as(*align(1) Int, @ptrCast(dest[pen..][0..copy_len])).* = @as(*align(1) const Int, @ptrCast(src[pen..][0..copy_len])).*;
+ @as(*align(1) Int, @ptrCast(dest[last..][0..copy_len])).* = @as(*align(1) const Int, @ptrCast(src[last..][0..copy_len])).*;
}
test "memcpy" {