[flang-commits] [flang] ea5b205 - [flang][runtime] Don't crash after surviving internal output overflow
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Sat Jun 4 08:55:42 PDT 2022
Author: Peter Klausler
Date: 2022-06-04T08:47:13-07:00
New Revision: ea5b205bb89508613ee0a57ccbfd6924c4a9586b
URL: https://github.com/llvm/llvm-project/commit/ea5b205bb89508613ee0a57ccbfd6924c4a9586b
DIFF: https://github.com/llvm/llvm-project/commit/ea5b205bb89508613ee0a57ccbfd6924c4a9586b.diff
LOG: [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
Added:
Modified:
flang/runtime/internal-unit.cpp
Removed:
################################################################################
diff --git a/flang/runtime/internal-unit.cpp b/flang/runtime/internal-unit.cpp
index 39a8e4b2c9c4..9f1d6c572c32 100644
--- a/flang/runtime/internal-unit.cpp
+++ b/flang/runtime/internal-unit.cpp
@@ -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();
}
}
More information about the flang-commits
mailing list