Skip to content

Commit

Permalink
[flang][runtime] Fix BACKSPACE over an empty record
Browse files Browse the repository at this point in the history
The implementation of BACKSPACE on a variable-length sequential formatted
file has a bug that prevents it from working on an empty record.

Differential Revision: https://reviews.llvm.org/D154750
  • Loading branch information
klausler committed Jul 7, 2023
1 parent 3c0ae1f commit 16e61eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flang/runtime/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ void ExternalFileUnit::BackspaceVariableUnformattedRecord(
// There's no portable memrchr(), unfortunately, and strrchr() would
// fail on a record with a NUL, so we have to do it the hard way.
static const char *FindLastNewline(const char *str, std::size_t length) {
for (const char *p{str + length}; p-- > str;) {
for (const char *p{str + length}; p >= str; p--) {
if (*p == '\n') {
return p;
}
Expand Down

0 comments on commit 16e61eb

Please sign in to comment.