zig

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

commit cbc3c0dc594341faddb8841fb466254f2f6f3b35 (tree)
parent cb9821a827f972252f8c02775bd2df07435f04c6
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;