[flang-commits] [PATCH] D155224: [flang][unittests] Fix recent snprintf() changes to use correct buffer lengths

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 17 13:12:12 PDT 2023


klausler updated this revision to Diff 541204.
klausler added a comment.

clang-format


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

https://reviews.llvm.org/D155224

Files:
  flang/unittests/Decimal/quick-sanity-test.cpp
  flang/unittests/Decimal/thorough-test.cpp


Index: flang/unittests/Decimal/thorough-test.cpp
===================================================================
--- flang/unittests/Decimal/thorough-test.cpp
+++ flang/unittests/Decimal/thorough-test.cpp
@@ -51,7 +51,8 @@
       if (*q == '-' || *q == '+') {
         ++expo;
       }
-      std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
+      std::snprintf(q + result.length,
+          buffer + sizeof buffer - (q + result.length), "e%d", expo);
     }
     const char *p{q};
     auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};
Index: flang/unittests/Decimal/quick-sanity-test.cpp
===================================================================
--- flang/unittests/Decimal/quick-sanity-test.cpp
+++ flang/unittests/Decimal/quick-sanity-test.cpp
@@ -53,7 +53,8 @@
       ++expo;
     }
     if (q >= buffer && q < buffer + sizeof buffer) {
-      std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
+      std::snprintf(q + result.length,
+          buffer + sizeof buffer - (q + result.length), "e%d", expo);
     }
     const char *p{q};
     auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155224.541204.patch
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230717/ca824ab6/attachment.bin>


More information about the flang-commits mailing list