diff --git a/flang/runtime/buffer.h b/flang/runtime/buffer.h --- a/flang/runtime/buffer.h +++ b/flang/runtime/buffer.h @@ -94,7 +94,7 @@ start_ + (at - fileOffset_) + static_cast(bytes) > size_) { Flush(handler); - fileOffset_ = at; + Reset(at); Reallocate(bytes, handler); } dirty_ = true; diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -517,7 +517,7 @@ } connection.currentRecordNumber = rec; if (auto *unit{io.GetExternalFileUnit()}) { - unit->SetPosition(rec * *connection.recordLength); + unit->SetPosition((rec - 1) * *connection.recordLength); } return true; }