Skip to content

Commit 18b9563

Browse files
authored
Prevent percentage memory calculation from overflowing (#73)
1 parent 5a980b1 commit 18b9563

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/limits/Misc/MemoryAvailable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ struct MemoryLimit : public SimpleAdjuster
2323
MEMORYSTATUSEX sysmem = { sizeof(sysmem) };
2424
if(GlobalMemoryStatusEx(&sysmem))
2525
{
26-
memory = uint32_t(sysmem.ullTotalPhys * std::stoul(value.substr(0, value.size() - 1)) / 100);
26+
auto calcmem = sysmem.ullTotalPhys * (std::stoul(value.substr(0, value.size() - 1)) / 100.0);
27+
memory = calcmem > UINT32_MAX ? UINT32_MAX : uint32_t(calcmem); // use the maximum value of uint32_t (if the calculated value exceeds the capacity)
2728
}
2829
}
2930
else

0 commit comments

Comments
 (0)