Commit 224fca7e0e

Ryan Liptak <squeek502@hotmail.com>
2025-08-28 07:16:21
process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize
Fixes #25038
1 parent 2b73c28
Changed files (1)
lib
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;