Skip to content

[flang][runtime] Skip unused truncated list-directed character input #118320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Dec 2, 2024

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

Fixes #118277.

@klausler klausler requested a review from vdonaldson December 2, 2024 16:38
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Dec 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 2, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

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

Fixes #118277.


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

1 Files Affected:

  • (modified) flang/runtime/edit-input.cpp (+6-3)
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, ' ');

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

Fixes llvm#118277.
@klausler klausler merged commit 9b64811 into llvm:main Dec 2, 2024
8 checks passed
@klausler klausler deleted the bug118277 branch December 2, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] : read character array
2 participants