[flang-commits] [flang] 16e61eb - [flang][runtime] Fix BACKSPACE over an empty record

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Jul 7 15:55:03 PDT 2023


Author: Peter Klausler
Date: 2023-07-07T15:54:34-07:00
New Revision: 16e61eb0c4d333fd589f94ddf40a37602d3eae93

URL: https://github.com/llvm/llvm-project/commit/16e61eb0c4d333fd589f94ddf40a37602d3eae93
DIFF: https://github.com/llvm/llvm-project/commit/16e61eb0c4d333fd589f94ddf40a37602d3eae93.diff

LOG: [flang][runtime] Fix BACKSPACE over an empty record

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

Added: 
    

Modified: 
    flang/runtime/unit.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp
index 5e8db046ca3b0c..1c8432328848e0 100644
--- a/flang/runtime/unit.cpp
+++ b/flang/runtime/unit.cpp
@@ -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;
     }


        


More information about the flang-commits mailing list