Skip to content

[flang][runtime] Skip unused truncated list-directed character input #118320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions flang/runtime/edit-input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,10 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
return false;
}
// Undelimited list-directed character input: stop at a value separator
// or the end of the current record. Subtlety: the "remaining" count
// here is a dummy that's used to avoid the interpretation of separators
// in NextInField.
Fortran::common::optional<int> remaining{length > 0 ? maxUTF8Bytes : 0};
while (Fortran::common::optional<char32_t> next{
io.NextInField(remaining, edit)}) {
// or the end of the current record.
while (auto ch{io.GetCurrentChar(byteCount)}) {
bool isSep{false};
switch (*next) {
switch (*ch) {
case ' ':
case '\t':
case '/':
Expand All @@ -1003,11 +999,17 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
break;
}
if (isSep) {
remaining = 0;
} else {
*x++ = *next;
remaining = --length > 0 ? maxUTF8Bytes : 0;
break;
}
if (length > 0) {
*x++ = *ch;
--length;
} else if (edit.IsNamelist()) {
// GNU compatibility
break;
}
io.HandleRelativePosition(byteCount);
io.GotChar(byteCount);
}
Fortran::runtime::fill_n(x, length, ' ');
return true;
Expand Down
Loading