[flang-commits] [PATCH] D145745: [flang][runtime] Catch infinite unlimited format repetition better

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Mar 10 09:35:46 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa1db3e6274cf: [flang][runtime] Catch infinite unlimited format repetition better (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145745/new/

https://reviews.llvm.org/D145745

Files:
  flang/runtime/format-implementation.h


Index: flang/runtime/format-implementation.h
===================================================================
--- flang/runtime/format-implementation.h
+++ flang/runtime/format-implementation.h
@@ -212,7 +212,7 @@
 // format validator gauntlet.
 template <typename CONTEXT>
 int FormatControl<CONTEXT>::CueUpNextDataEdit(Context &context, bool stop) {
-  int unlimitedLoopCheck{-1};
+  bool hitUnlimitedLoopEnd{false};
   // Do repetitions remain on an unparenthesized data edit?
   while (height_ > 1 && format_[stack_[height_ - 1].start] != '(') {
     offset_ = stack_[height_ - 1].start;
@@ -267,7 +267,6 @@
       RUNTIME_CHECK(context, format_[stack_[height_].start] == '(');
       if (unlimited || height_ == 0) {
         stack_[height_].remaining = Iteration::unlimited;
-        unlimitedLoopCheck = offset_ - 1;
       } else if (repeat) {
         if (*repeat <= 0) {
           *repeat = 1; // error recovery
@@ -305,12 +304,13 @@
               restart);
           return 0;
         }
-        if (offset_ == unlimitedLoopCheck) {
+        if (hitUnlimitedLoopEnd) {
           ReportBadFormat(context,
               "Unlimited repetition in FORMAT lacks data edit descriptors",
               restart);
           return 0;
         }
+        hitUnlimitedLoopEnd = true;
         offset_ = restart;
       } else if (stack_[height_ - 1].remaining-- > 0) {
         offset_ = restart;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145745.504184.patch
Type: text/x-patch
Size: 1407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230310/234e75e9/attachment-0001.bin>


More information about the flang-commits mailing list