Skip to content

Commit f4b4ae3

Browse files
committed
[flang][runtime] Skip unused truncated list-directed character input
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 a475180 commit f4b4ae3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

flang/runtime/edit-input.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
979979
// or the end of the current record. Subtlety: the "remaining" count
980980
// here is a dummy that's used to avoid the interpretation of separators
981981
// in NextInField.
982-
Fortran::common::optional<int> remaining{length > 0 ? maxUTF8Bytes : 0};
982+
Fortran::common::optional<int> remaining{maxUTF8Bytes};
983983
while (Fortran::common::optional<char32_t> next{
984984
io.NextInField(remaining, edit)}) {
985985
bool isSep{false};
@@ -1005,8 +1005,11 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
10051005
if (isSep) {
10061006
remaining = 0;
10071007
} else {
1008-
*x++ = *next;
1009-
remaining = --length > 0 ? maxUTF8Bytes : 0;
1008+
if (length > 0) {
1009+
*x++ = *next;
1010+
--length;
1011+
}
1012+
remaining = maxUTF8Bytes;
10101013
}
10111014
}
10121015
Fortran::runtime::fill_n(x, length, ' ');

0 commit comments

Comments
 (0)