Skip to content

Commit bddf5d2

Browse files
authored
[flang][runtime] Fix BACKSPACE-WRITE on variable-length unformatted file (llvm#72732)
A subtle bug in buffer management is being caused by a WRITE on an unformatted file with variable-length records after one or more BACKSPACEs and some READs. An attempt at a minor optimization in BACKSPACE kept the footer of the previous record in the unit's buffer, in case more BACKSPACEs were to follow. If a later WRITE takes place instead, the buffer's frame would still cover that footer, but its content would be lost when the buffer became dirty on its first modification, and the footer in the file would be overwritten with stale buffer contents. As WriteFrame() implies the intent to define all the bytes in the identified range, the trick being used in BACKSPACE with its adjustment to frameOffsetInFile_ breaks any later WRITE... and so we just can't do it. Fixes llvm#72599.
1 parent 2484469 commit bddf5d2

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

flang/runtime/unit.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,6 @@ void ExternalFileUnit::BackspaceVariableUnformattedRecord(
825825
return;
826826
}
827827
frameOffsetInFile_ -= *recordLength + 2 * headerBytes;
828-
if (frameOffsetInFile_ >= headerBytes) {
829-
frameOffsetInFile_ -= headerBytes;
830-
recordOffsetInFrame_ = headerBytes;
831-
}
832828
auto need{static_cast<std::size_t>(
833829
recordOffsetInFrame_ + sizeof header + *recordLength)};
834830
got = ReadFrame(frameOffsetInFile_, need, handler);

0 commit comments

Comments
 (0)