[flang-commits] [PATCH] D127431: [flang][runtime] Don't loop in runtime if blank appears in BOZ input
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Jun 9 12:16:58 PDT 2022
klausler created this revision.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D127431
Files:
flang/runtime/edit-input.cpp
Index: flang/runtime/edit-input.cpp
===================================================================
--- flang/runtime/edit-input.cpp
+++ flang/runtime/edit-input.cpp
@@ -21,14 +21,16 @@
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 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127431.435640.patch
Type: text/x-patch
Size: 1054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220609/2c6dddb5/attachment-0001.bin>
More information about the flang-commits
mailing list