[flang-commits] [flang] [flang][runtime] Fix integer overflow check for FORMATs (PR #79471)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Thu Jan 25 09:12:48 PST 2024
================
@@ -85,8 +85,8 @@ int FormatControl<CONTEXT>::GetIntField(
ch = PeekNext();
}
while (ch >= '0' && ch <= '9') {
- if (result >
- std::numeric_limits<int>::max() / 10 - (static_cast<int>(ch) - '0')) {
+ constexpr int tenth{std::numeric_limits<int>::max() / 10};
+ if (result > tenth || ch - '0' > std::numeric_limits<int>::max() - result) {
----------------
vzakhari wrote:
Not sure, but shouldn't it look like `|| ch - '0' > std::numeric_limits<int>::max() - result * 10`?
https://github.com/llvm/llvm-project/pull/79471
More information about the flang-commits
mailing list