[flang-commits] [PATCH] D127428: [flang][runtime] Detect overflow of fixed-sized exponent output field

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jun 13 16:15:20 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb52dda8ab6f: [flang][runtime] Detect overflow of fixed-sized exponent output field (authored by klausler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127428

Files:
  flang/runtime/edit-output.cpp
  flang/runtime/edit-output.h


Index: flang/runtime/edit-output.h
===================================================================
--- flang/runtime/edit-output.h
+++ flang/runtime/edit-output.h
@@ -52,6 +52,7 @@
     return *p < '0' || *p > '9';
   }
 
+  // Returns null when the exponent overflows a fixed-size output field.
   const char *FormatExponent(int, const DataEdit &edit, int &length);
   bool EmitPrefix(const DataEdit &, std::size_t length, std::size_t width);
   bool EmitSuffix(const DataEdit &);
Index: flang/runtime/edit-output.cpp
===================================================================
--- flang/runtime/edit-output.cpp
+++ flang/runtime/edit-output.cpp
@@ -182,8 +182,10 @@
     *--exponent = '0' + e - 10 * quotient;
     e = quotient;
   }
+  bool overflow{false};
   if (edit.expoDigits) {
     if (int ed{*edit.expoDigits}) { // Ew.dEe with e > 0
+      overflow = exponent + ed < eEnd;
       while (exponent > exponent_ + 2 /*E+*/ && exponent + ed > eEnd) {
         *--exponent = '0';
       }
@@ -200,7 +202,7 @@
     *--exponent = edit.descriptor == 'D' ? 'D' : 'E'; // not 'G'
   }
   length = eEnd - exponent;
-  return exponent;
+  return overflow ? nullptr : exponent;
 }
 
 bool RealOutputEditingBase::EmitPrefix(
@@ -353,7 +355,7 @@
         1 /*'.'*/ + zeroesAfterPoint + digitsAfterPoint + trailingZeroes +
         expoLength};
     int width{editWidth > 0 ? editWidth : totalLength};
-    if (totalLength > width) {
+    if (totalLength > width || !exponent) {
       return io_.EmitRepeated('*', width);
     }
     if (totalLength < width && digitsBeforePoint == 0 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127428.436597.patch
Type: text/x-patch
Size: 1595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220613/1614d447/attachment-0001.bin>


More information about the flang-commits mailing list