[flang][runtime] Don't crash after surviving internal output overflow

After the program has survived its attempt to overflow the output buffer
with an internal WRITE using ERR=, IOSTAT=, &/or IOMSG=, don't crash
by accidentally blank-filling the next record that usually doesn't exist.

Differential Revision: https://reviews.llvm.org/D127024
This commit is contained in:
Peter Klausler 2022-05-31 10:17:20 -07:00
parent ea1a69d66d
commit ea5b205bb8
1 changed files with 3 additions and 1 deletions

View File

@ -41,7 +41,9 @@ template <Direction DIR> void InternalDescriptorUnit<DIR>::EndIoStatement() {
if constexpr (DIR == Direction::Output) {
// Clear the remainder of the current record if anything was written
// to it, or if it is the only record.
if (endfileRecordNumber.value_or(-1) == 2 || furthestPositionInRecord > 0) {
auto end{endfileRecordNumber.value_or(0)};
if (currentRecordNumber < end &&
(end == 2 || furthestPositionInRecord > 0)) {
BlankFillOutputRecord();
}
}