[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 14:25:45 PDT 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
Ew.d and Dw.d output edit descriptors should respect limitations from
the standard on the value of a kP scale factor with respect to the
digit count (d), at least for values of k other than zero.
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.424611.patch
Type: text/x-patch
Size: 1727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220422/d7c0f263/attachment.bin>
More information about the flang-commits
mailing list