Skip to content

Commit

Permalink
Prevent percentage memory calculation from overflowing (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
bscout9956 authored Nov 10, 2024
1 parent 5a980b1 commit 18b9563
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/limits/Misc/MemoryAvailable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct MemoryLimit : public SimpleAdjuster
MEMORYSTATUSEX sysmem = { sizeof(sysmem) };
if(GlobalMemoryStatusEx(&sysmem))
{
memory = uint32_t(sysmem.ullTotalPhys * std::stoul(value.substr(0, value.size() - 1)) / 100);
auto calcmem = sysmem.ullTotalPhys * (std::stoul(value.substr(0, value.size() - 1)) / 100.0);
memory = calcmem > UINT32_MAX ? UINT32_MAX : uint32_t(calcmem); // use the maximum value of uint32_t (if the calculated value exceeds the capacity)
}
}
else
Expand Down

0 comments on commit 18b9563

Please sign in to comment.