[flang-commits] [flang] 850097d - [flang][runtime] Don't loop in runtime if blank appears in BOZ input
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Jun 13 16:31:00 PDT 2022
Author: Peter Klausler
Date: 2022-06-13T16:26:50-07:00
New Revision: 850097d6dca6eec41e74f8823949f626735d00fe
URL: https://github.com/llvm/llvm-project/commit/850097d6dca6eec41e74f8823949f626735d00fe
DIFF: https://github.com/llvm/llvm-project/commit/850097d6dca6eec41e74f8823949f626735d00fe.diff
LOG: [flang][runtime] Don't loop in runtime if blank appears in BOZ input
The code for scanning BOZ input allows for blanks and tabs to appear,
but can hang if they do and the BOZ input value is not followed by
extra valid digits; the repositioning for the second sweep simply
needed to be done in units of character, not valid digits.
Differential Revision: https://reviews.llvm.org/D127431
Added:
Modified:
flang/runtime/edit-input.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index cfcb98b68144..57a935fd5765 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -21,14 +21,16 @@ static bool EditBOZInput(
IoStatementState &io, const DataEdit &edit, void *n, std::size_t bytes) {
std::optional<int> remaining;
std::optional<char32_t> next{io.PrepareInput(edit, remaining)};
- if (*next == '0') {
+ if (next.value_or('?') == '0') {
do {
next = io.NextInField(remaining, edit);
} while (next && *next == '0');
}
// Count significant digits after any leading white space & zeroes
int digits{0};
+ int chars{0};
for (; next; next = io.NextInField(remaining, edit)) {
+ ++chars;
char32_t ch{*next};
if (ch == ' ' || ch == '\t') {
continue;
@@ -52,7 +54,7 @@ static bool EditBOZInput(
return false;
}
// Reset to start of significant digits
- io.HandleRelativePosition(-digits);
+ io.HandleRelativePosition(-chars);
remaining.reset();
// Make a second pass now that the digit count is known
std::memset(n, 0, bytes);
More information about the flang-commits
mailing list