Skip to content

Commit 9b64811

Browse files
authored
[flang][runtime] Skip unused truncated list-directed character input (#118320)
When reading non-delimited list-directed character input, read the whole field even if it doesn't fit into the variable. Fixes #118277.
1 parent dfbc80f commit 9b64811

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

flang/runtime/edit-input.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,10 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
976976
return false;
977977
}
978978
// Undelimited list-directed character input: stop at a value separator
979-
// or the end of the current record. Subtlety: the "remaining" count
980-
// here is a dummy that's used to avoid the interpretation of separators
981-
// in NextInField.
982-
Fortran::common::optional<int> remaining{length > 0 ? maxUTF8Bytes : 0};
983-
while (Fortran::common::optional<char32_t> next{
984-
io.NextInField(remaining, edit)}) {
979+
// or the end of the current record.
980+
while (auto ch{io.GetCurrentChar(byteCount)}) {
985981
bool isSep{false};
986-
switch (*next) {
982+
switch (*ch) {
987983
case ' ':
988984
case '\t':
989985
case '/':
@@ -1003,11 +999,17 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
1003999
break;
10041000
}
10051001
if (isSep) {
1006-
remaining = 0;
1007-
} else {
1008-
*x++ = *next;
1009-
remaining = --length > 0 ? maxUTF8Bytes : 0;
1002+
break;
1003+
}
1004+
if (length > 0) {
1005+
*x++ = *ch;
1006+
--length;
1007+
} else if (edit.IsNamelist()) {
1008+
// GNU compatibility
1009+
break;
10101010
}
1011+
io.HandleRelativePosition(byteCount);
1012+
io.GotChar(byteCount);
10111013
}
10121014
Fortran::runtime::fill_n(x, length, ' ');
10131015
return true;

0 commit comments

Comments
 (0)