[flang-commits] [flang] [flang] fix possible iterator underflow (PR #115754)
via flang-commits
flang-commits at lists.llvm.org
Mon Nov 11 10:36:32 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: None (Originns)
<details>
<summary>Changes</summary>
Replaced do-while with while loop in SemanticsContext::SearchScopeIndex(parser::CharBlock source) to prevent iterator underflow when upper_bound returns begin(). This ensures the iterator check happens before decrementing.
---
Full diff: https://github.com/llvm/llvm-project/pull/115754.diff
1 Files Affected:
- (modified) flang/lib/Semantics/semantics.cpp (+2-2)
``````````diff
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index 58dc1f218b56f4..dac781566f1a8e 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -415,12 +415,12 @@ auto SemanticsContext::SearchScopeIndex(parser::CharBlock source)
if (!scopeIndex_.empty()) {
auto iter{scopeIndex_.upper_bound(source)};
auto begin{scopeIndex_.begin()};
- do {
+ while (iter != begin) {
--iter;
if (iter->first.Contains(source)) {
return iter;
}
- } while (iter != begin);
+ }
}
return scopeIndex_.end();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/115754
More information about the flang-commits
mailing list