[flang-commits] [flang] [flang][runtime] Skip unused truncated list-directed character input (PR #118320)

via flang-commits flang-commits at lists.llvm.org
Mon Dec 2 08:39:33 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

When reading non-delimited list-directed character input, read the whole field even if it doesn't fit into the variable.

Fixes https://github.com/llvm/llvm-project/issues/118277.

---
Full diff: https://github.com/llvm/llvm-project/pull/118320.diff


1 Files Affected:

- (modified) flang/runtime/edit-input.cpp (+6-3) 


``````````diff
diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index 2cee35e23f31a3..a8c52ea93a6109 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -979,7 +979,7 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
   // or the end of the current record.  Subtlety: the "remaining" count
   // here is a dummy that's used to avoid the interpretation of separators
   // in NextInField.
-  Fortran::common::optional<int> remaining{length > 0 ? maxUTF8Bytes : 0};
+  Fortran::common::optional<int> remaining{maxUTF8Bytes};
   while (Fortran::common::optional<char32_t> next{
       io.NextInField(remaining, edit)}) {
     bool isSep{false};
@@ -1005,8 +1005,11 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
     if (isSep) {
       remaining = 0;
     } else {
-      *x++ = *next;
-      remaining = --length > 0 ? maxUTF8Bytes : 0;
+      if (length > 0) {
+        *x++ = *next;
+        --length;
+      }
+      remaining = maxUTF8Bytes;
     }
   }
   Fortran::runtime::fill_n(x, length, ' ');

``````````

</details>


https://github.com/llvm/llvm-project/pull/118320


More information about the flang-commits mailing list