Cast to larger type before doing arithmetic to avoid signed integer overflow

https://godbolt.org/z/soTad4zEq

this godbolt links shows that it is UB to multiply then cast if the amount is large enough
This commit is contained in:
ZXShady authored and Chris Thrasher committed 2024-09-28 19:45:28 -06:00
1 parent f297287951
commit b626f65ee5
2 files changed
+4 -1

No files matched your search

+3
View File
@@ -28,4 +28,7 @@ TEST_CASE("[System] sfTime")
CHECK(sfSeconds(10).microseconds == 10'000'000);
CHECK(sfMilliseconds(10).microseconds == 10'000);
CHECK(sfMicroseconds(10).microseconds == 10);
CHECK(sfMilliseconds(std::numeric_limits<int32_t>::max()).microseconds == 2'147'483'647'000);
CHECK(sfMicroseconds(std::numeric_limits<int64_t>::max()).microseconds == std::numeric_limits<int64_t>::max());
}