Fix integer conversion on 32-bit

This commit is contained in:
Alexander Shabalin
2021-06-17 13:25:09 +03:00
committed by Space
parent eaed67df29
commit 91a852d3fd
@@ -58,6 +58,10 @@ size_t kotlin::GetPeakResidentSetSizeBytes() noexcept {
extern "C" RUNTIME_NOTHROW KLong Kotlin_MemoryUsageInfo_getPeakResidentSetSizeBytes() {
auto result = kotlin::GetPeakResidentSetSizeBytes();
auto boundedResult = std::min<decltype(result)>(result, std::numeric_limits<KLong>::max());
return static_cast<KLong>(boundedResult);
// TODO: Need a common implementation for such conversions.
if constexpr (sizeof(decltype(result)) >= sizeof(KLong)) {
return static_cast<KLong>(std::min<decltype(result)>(result, std::numeric_limits<KLong>::max()));
} else {
return std::min<KLong>(result, std::numeric_limits<KLong>::max());
}
}