zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 224fca7e0e1cfe1bf27178ecb4e53d4f88fb9abf (tree)
parent 2b73c28cec9a5c75ab064f1ebd88b12aa64d22dd
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Wed, 27 Aug 2025 22:16:21 -0700

process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize

Fixes #25038

Diffstat:
Mlib/std/process.zig | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/std/process.zig b/lib/std/process.zig @@ -1753,7 +1753,8 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 { if (std.os.linux.E.init(result) != .SUCCESS) { return error.UnknownTotalSystemMemory; } - return info.totalram * info.mem_unit; + // Promote to u64 to avoid overflow on systems where info.totalram is a 32-bit usize + return @as(u64, info.totalram) * info.mem_unit; }, .freebsd => { var physmem: c_ulong = undefined;