[flang-commits] [PATCH] D124300: [flang][runtime] Enforce some limits on kP scale factors

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Apr 22 16:51:55 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc02abb68cd88: [flang][runtime] Enforce some limits on kP scale factors (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124300

Files:
  flang/include/flang/Runtime/iostat.h
  flang/runtime/edit-output.cpp
  flang/runtime/iostat.cpp


Index: flang/runtime/iostat.cpp
===================================================================
--- flang/runtime/iostat.cpp
+++ flang/runtime/iostat.cpp
@@ -81,6 +81,8 @@
     return "UNIT number is out of range";
   case IostatBadRealInput:
     return "Bad REAL input value";
+  case IostatBadScaleFactor:
+    return "Bad REAL output scale factor (kP)";
   default:
     return nullptr;
   }
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -196,9 +196,21 @@
   int scale{isEN || isES ? 1 : edit.modes.scale}; // 'kP' value
   int zeroesAfterPoint{0};
   if (scale < 0) {
+    if (scale <= -editDigits) {
+      io_.GetIoErrorHandler().SignalError(IostatBadScaleFactor,
+          "Scale factor (kP) %d cannot be less than -d (%d)", scale,
+          -editDigits);
+      return false;
+    }
     zeroesAfterPoint = -scale;
     significantDigits = std::max(0, significantDigits - zeroesAfterPoint);
   } else if (scale > 0) {
+    if (scale >= editDigits + 2) {
+      io_.GetIoErrorHandler().SignalError(IostatBadScaleFactor,
+          "Scale factor (kP) %d cannot be greater than d+2 (%d)", scale,
+          editDigits + 2);
+      return false;
+    }
     ++significantDigits;
     scale = std::min(scale, significantDigits + 1);
   }
Index: flang/include/flang/Runtime/iostat.h
===================================================================
--- flang/include/flang/Runtime/iostat.h
+++ flang/include/flang/Runtime/iostat.h
@@ -69,6 +69,7 @@
   IostatUTF8Decoding,
   IostatUnitOverflow,
   IostatBadRealInput,
+  IostatBadScaleFactor,
 };
 
 const char *IostatErrorString(int);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124300.424666.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220422/d291cdb3/attachment.bin>


More information about the flang-commits mailing list