[flang-commits] [flang] [flang][runtime] Fix integer overflow check in FORMAT (PR #79368)

via flang-commits flang-commits at lists.llvm.org
Wed Jan 24 16:01:38 PST 2024


================
@@ -214,15 +215,13 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
   case '7':
   case '8':
   case '9': {
-    int64_t lastValue;
     const CHAR *lastCursor;
     integerValue_ = 0;
     bool overflow{false};
     do {
-      lastValue = integerValue_;
       lastCursor = cursor_;
       integerValue_ = 10 * integerValue_ + c - '0';
-      if (lastValue > integerValue_) {
+      if (integerValue_ > std::numeric_limits<int>::max()) {
----------------
vdonaldson wrote:

Yes. So what should be a positive value becomes negative on overflow. If the type were unsigned, the overflow value would be positive but smaller. I think both signed and unsigned underlying types have this property. (It's been a long time since I looked at this in detail.)

https://github.com/llvm/llvm-project/pull/79368


More information about the flang-commits mailing list