From 90d0925a12814cdecc3210db43a2f3c4fbc8511d Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Wed, 13 Aug 2025 17:46:12 +0200 Subject: [PATCH 01/10] lib/std/os/linux/test.zig: fadvise: don't write to file it isn't necessary for the test and triggered a valgrind warning --- lib/std/os/linux/test.zig | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index e38687dbde10..023e676c28fb 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -120,9 +120,6 @@ test "fadvise" { var file = try tmp.dir.createFile(tmp_file_name, .{}); defer file.close(); - var buf: [2048]u8 = undefined; - try file.writeAll(&buf); - const ret = linux.fadvise(file.handle, 0, 0, linux.POSIX_FADV.SEQUENTIAL); try expectEqual(@as(usize, 0), ret); } From c7bff024022845ea846f5b76304489e5464c12d9 Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Wed, 13 Aug 2025 17:52:20 +0200 Subject: [PATCH 02/10] lib/std/os/linux/test.zig: futex v1: supply second pointer to CMP_REQUEUE fixes a valgrind warning --- lib/std/os/linux/test.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 023e676c28fb..375ff36fb508 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -241,7 +241,7 @@ test "futex v1" { try expectEqual(0, rc); // CMP_REQUEUE - val3 mismatch - rc = linux.futex(&lock.raw, .{ .cmd = .CMP_REQUEUE, .private = true }, 2, .{ .val2 = 0 }, null, 99); + rc = linux.futex(&lock.raw, .{ .cmd = .CMP_REQUEUE, .private = true }, 2, .{ .val2 = 0 }, &lock.raw, 99); try expectEqual(.AGAIN, linux.E.init(rc)); // CMP_REQUEUE - requeue (but no waiters, so ... not much) From 74f2a387556c25a6e5df092052db741c58852e9a Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Wed, 13 Aug 2025 17:58:12 +0200 Subject: [PATCH 03/10] lib/std/os/linux/IoUring.zig: write_fixed/read_fixed: initialize entire buffer fixes a valgrind warning --- lib/std/os/linux/IoUring.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 25d4d88fd02f..1a3e5c86b40f 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -2178,7 +2178,7 @@ test "write_fixed/read_fixed" { defer file.close(); const fd = file.handle; - var raw_buffers: [2][11]u8 = undefined; + var raw_buffers: [2][11]u8 = @splat(@splat(0)); // First buffer will be written to the file. @memset(&raw_buffers[0], 'z'); raw_buffers[0][0.."foobar".len].* = "foobar".*; From 1fcc2c0232ea1105678638b9c0c759e32f722b86 Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Wed, 13 Aug 2025 18:11:29 +0200 Subject: [PATCH 04/10] lib/std/os/linux/IoUring.zig: disable false positive valgrind warning the buffers are set to 0 after reading provide_buffers: triggered when checking cqe.user_data remove_buffers: expectEqualSlices --- lib/std/os/linux/IoUring.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 1a3e5c86b40f..47277ce29839 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -3206,6 +3206,7 @@ test "provide_buffers: read" { const buffer_len = 128; var buffers: [4][buffer_len]u8 = undefined; + std.valgrind.memcheck.makeMemDefinedIfAddressable(std.mem.sliceAsBytes(&buffers)); // Provide 4 buffers @@ -3338,6 +3339,7 @@ test "remove_buffers" { const buffer_len = 128; var buffers: [4][buffer_len]u8 = undefined; + std.valgrind.memcheck.makeMemDefinedIfAddressable(std.mem.sliceAsBytes(&buffers)); // Provide 4 buffers From 1c179d8e1b82cad8b31fb333e374cad76814645d Mon Sep 17 00:00:00 2001 From: rpkak Date: Wed, 13 Aug 2025 19:40:33 +0200 Subject: [PATCH 05/10] lib/std/os/linux/IoUring.zig: BufferGroup: get: disable valgrind warning --- lib/std/os/linux/IoUring.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 47277ce29839..478c5a67e04e 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -1704,7 +1704,9 @@ pub const BufferGroup = struct { pub fn get(self: *BufferGroup, cqe: linux.io_uring_cqe) ![]u8 { const buffer_id = try cqe.buffer_id(); const used_len = @as(usize, @intCast(cqe.res)); - return self.get_by_id(buffer_id)[0..used_len]; + const buf = self.get_by_id(buffer_id)[0..used_len]; + std.valgrind.memcheck.makeMemDefinedIfAddressable(buf); + return buf; } // Release buffer from CQE to the kernel. From c02046ef4f2a62877ef74eb7c8efe7c687912f17 Mon Sep 17 00:00:00 2001 From: rpkak Date: Wed, 13 Aug 2025 19:45:17 +0200 Subject: [PATCH 06/10] lib/std/os/linux/IoUring.zig: expect_buf_grp_cqe: uninitialized memory fix valgrind warning --- lib/std/os/linux/IoUring.zig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 478c5a67e04e..67933d2436c1 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -4420,9 +4420,7 @@ fn expect_buf_grp_cqe( try testing.expectEqual(posix.E.SUCCESS, cqe.err()); // get buffer from pool - const buffer_id = try cqe.buffer_id(); - const len = @as(usize, @intCast(cqe.res)); - const buf = buf_grp.get_by_id(buffer_id)[0..len]; + const buf = try buf_grp.get(cqe); try testing.expectEqualSlices(u8, expected, buf); return cqe; From a07c126e273da6ebf34ee2eb2cde88cac9038827 Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Thu, 14 Aug 2025 09:15:32 +0200 Subject: [PATCH 07/10] lib/std/os/linux/IoUring.zig: test.waitid: initialize siginfo disabling the false positive warning is a bit tricky --- lib/std/os/linux/IoUring.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 67933d2436c1..6c536b61a19d 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -4056,7 +4056,7 @@ test "waitid" { posix.exit(7); } - var siginfo: posix.siginfo_t = undefined; + var siginfo = std.mem.zeroes(posix.siginfo_t); _ = try ring.waitid(0, .PID, pid, &siginfo, posix.W.EXITED, 0); try testing.expectEqual(1, try ring.submit()); From 75da24ee62afba4eb7ba4fcfcc92168752ba852e Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Thu, 14 Aug 2025 09:30:50 +0200 Subject: [PATCH 08/10] lib/std/os/linux/IoUring.zig: testSendRecv: disable valgrind warning --- lib/std/os/linux/IoUring.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index 6c536b61a19d..d284d07192e2 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -4601,6 +4601,8 @@ fn testSendRecv(ring: *IoUring, send_fd: posix.socket_t, recv_fd: posix.socket_t try testing.expectEqual(posix.E.SUCCESS, cqe.err()); recv_len += @intCast(cqe.res); } + // if this is not the case, the check fails + std.valgrind.memcheck.makeMemDefinedIfAddressable(&buffer_recv); // inspect recv buffer try testing.expectEqualSlices(u8, buffer_send, buffer_recv[0..buffer_send.len]); From 59bb2a745845e1b65195f8d95e91eb4819333e5c Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Thu, 14 Aug 2025 09:35:18 +0200 Subject: [PATCH 09/10] lib/std/os/linux/IoUring.zig: test.statx: disable valgrind warning --- lib/std/os/linux/IoUring.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index d284d07192e2..e67abefffda5 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -2706,6 +2706,8 @@ test "statx" { .BADF => return error.SkipZigTest, else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), } + // buf is initialized after a successful copy_cqe + std.valgrind.memcheck.makeMemDefinedIfAddressable(std.mem.sliceAsBytes(std.mem.asBytes(&buf))); try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xaaaaaaaa, .res = 0, From 04a42c15a2bca901123e932f030dec84c37f8f99 Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Thu, 14 Aug 2025 10:11:19 +0200 Subject: [PATCH 10/10] lib/std/math/big/int.zig: Mutable.mulWrapNoAlias: pass initialized rma.limbs slice --- lib/std/math/big/int.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index b0380444f4dc..9630868d78b5 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -872,7 +872,7 @@ pub const Mutable = struct { @memset(rma.limbs[0..req_limbs], 0); - llmulacc(.add, allocator, rma.limbs, a_limbs, b_limbs); + llmulacc(.add, allocator, rma.limbs[0..req_limbs], a_limbs, b_limbs); rma.normalize(@min(req_limbs, a.limbs.len + b.limbs.len)); rma.positive = (a.positive == b.positive); rma.truncate(rma.toConst(), signedness, bit_count);