diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2025-08-27 22:16:21 -0700 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2025-08-28 17:05:39 +0200 |
| commit | 224fca7e0e1cfe1bf27178ecb4e53d4f88fb9abf (patch) | |
| tree | 6a896e02dc8412d396da2f3cb4d798e2d308cf2d /lib/std/process.zig | |
| parent | 2b73c28cec9a5c75ab064f1ebd88b12aa64d22dd (diff) | |
| download | zig-224fca7e0e1cfe1bf27178ecb4e53d4f88fb9abf.tar.gz zig-224fca7e0e1cfe1bf27178ecb4e53d4f88fb9abf.zip | |
process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize
Fixes #25038
Diffstat (limited to 'lib/std/process.zig')
| -rw-r--r-- | lib/std/process.zig | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/std/process.zig b/lib/std/process.zig index 1f86ca658a..8c113b128e 100644 --- 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; |
