[flang-commits] [PATCH] D108594: [flang] runtime: fix WRITE after BACKSPACE on variable-length file

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Aug 24 09:39:14 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb232a88c6fac: [flang] runtime: fix WRITE after BACKSPACE on variable-length file (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108594/new/

https://reviews.llvm.org/D108594

Files:
  flang/runtime/unit.cpp


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -258,13 +258,20 @@
     std::size_t elementBytes, IoErrorHandler &handler) {
   auto furthestAfter{std::max(furthestPositionInRecord,
       positionInRecord + static_cast<std::int64_t>(bytes))};
-  if (furthestAfter > recordLength.value_or(furthestAfter)) {
-    handler.SignalError(IostatRecordWriteOverrun,
-        "Attempt to write %zd bytes to position %jd in a fixed-size record of "
-        "%jd bytes",
-        bytes, static_cast<std::intmax_t>(positionInRecord),
-        static_cast<std::intmax_t>(*recordLength));
-    return false;
+  if (recordLength) {
+    // It is possible for recordLength to have a value now for a
+    // variable-length output record if the previous operation
+    // was a BACKSPACE.
+    if (!isFixedRecordLength) {
+      recordLength.reset();
+    } else if (furthestAfter > *recordLength) {
+      handler.SignalError(IostatRecordWriteOverrun,
+          "Attempt to write %zd bytes to position %jd in a fixed-size record "
+          "of %jd bytes",
+          bytes, static_cast<std::intmax_t>(positionInRecord),
+          static_cast<std::intmax_t>(*recordLength));
+      return false;
+    }
   }
   WriteFrame(frameOffsetInFile_, recordOffsetInFrame_ + furthestAfter, handler);
   if (positionInRecord > furthestPositionInRecord) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108594.368373.patch
Type: text/x-patch
Size: 1439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210824/4e5b6cdd/attachment.bin>


More information about the flang-commits mailing list