Skip to content

Commit 850097d

Browse files
committed
[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
1 parent f472c09 commit 850097d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

flang/runtime/edit-input.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ static bool EditBOZInput(
2121
IoStatementState &io, const DataEdit &edit, void *n, std::size_t bytes) {
2222
std::optional<int> remaining;
2323
std::optional<char32_t> next{io.PrepareInput(edit, remaining)};
24-
if (*next == '0') {
24+
if (next.value_or('?') == '0') {
2525
do {
2626
next = io.NextInField(remaining, edit);
2727
} while (next && *next == '0');
2828
}
2929
// Count significant digits after any leading white space & zeroes
3030
int digits{0};
31+
int chars{0};
3132
for (; next; next = io.NextInField(remaining, edit)) {
33+
++chars;
3234
char32_t ch{*next};
3335
if (ch == ' ' || ch == '\t') {
3436
continue;
@@ -52,7 +54,7 @@ static bool EditBOZInput(
5254
return false;
5355
}
5456
// Reset to start of significant digits
55-
io.HandleRelativePosition(-digits);
57+
io.HandleRelativePosition(-chars);
5658
remaining.reset();
5759
// Make a second pass now that the digit count is known
5860
std::memset(n, 0, bytes);

0 commit comments

Comments
 (0)