mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize
Fixes #25038
This commit is contained in:
parent
2b73c28cec
commit
224fca7e0e
1 changed files with 2 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue