[flang-commits] [PATCH] D154750: [flang][runtime] Fix BACKSPACE over an empty record

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 7 14:39:54 PDT 2023


klausler created this revision.
klausler added a reviewer: vzakhari.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

The implementation of BACKSPACE on a variable-length sequential formatted
file has a bug that prevents it from working on an empty record.


https://reviews.llvm.org/D154750

Files:
  flang/runtime/unit.cpp


Index: flang/runtime/unit.cpp
===================================================================
--- flang/runtime/unit.cpp
+++ flang/runtime/unit.cpp
@@ -843,7 +843,7 @@
 // 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;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154750.538272.patch
Type: text/x-patch
Size: 536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230707/273cdf3f/attachment-0001.bin>


More information about the flang-commits mailing list