aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorPeter Klausler <pklausler@nvidia.com>2023-07-17 13:10:36 -0700
committerPeter Klausler <pklausler@nvidia.com>2023-07-18 10:28:16 -0700
commitecd691750648b72b9e0ce6879fcfa60396693a77 (patch)
tree68febe4a45aef0f5d391d3b7d826ed718e8e0309 /flang
parent3336836dc21b7bea912b5bb2b72438b18b8cea04 (diff)
downloadllvm-ecd691750648b72b9e0ce6879fcfa60396693a77.zip
llvm-ecd691750648b72b9e0ce6879fcfa60396693a77.tar.gz
llvm-ecd691750648b72b9e0ce6879fcfa60396693a77.tar.bz2
[flang][unittests] Fix recent snprintf() changes to use correct buffer lengths
A recent patch replaced two sprintf() calls with snprintf(), but didn't use the right length for the remaining space in the buffer. Differential Revision: https://reviews.llvm.org/D155224
Diffstat (limited to 'flang')
-rw-r--r--flang/unittests/Decimal/quick-sanity-test.cpp3
-rw-r--r--flang/unittests/Decimal/thorough-test.cpp3
2 files changed, 4 insertions, 2 deletions
diff --git a/flang/unittests/Decimal/quick-sanity-test.cpp b/flang/unittests/Decimal/quick-sanity-test.cpp
index 74434c1..dafb075 100644
--- a/flang/unittests/Decimal/quick-sanity-test.cpp
+++ b/flang/unittests/Decimal/quick-sanity-test.cpp
@@ -53,7 +53,8 @@ void testReadback(float x, int flags) {
++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)};
diff --git a/flang/unittests/Decimal/thorough-test.cpp b/flang/unittests/Decimal/thorough-test.cpp
index 2261a1c..46951f3 100644
--- a/flang/unittests/Decimal/thorough-test.cpp
+++ b/flang/unittests/Decimal/thorough-test.cpp
@@ -51,7 +51,8 @@ void testReadback(float x, int flags) {
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)};