[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
Thu Jul 13 11:04:33 PDT 2023
klausler created this revision.
klausler added a reviewer: cseo.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
A recent patch replaced two sprintf() calls with snprintf(), but didn't
use the right length for the remaining space in the buffer.
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,7 @@
if (*q == '-' || *q == '+') {
++expo;
}
- std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
+ std::snprintf(q + result.length, sizeof buffer - (q + result.length - buffer), "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,7 @@
++expo;
}
if (q >= buffer && q < buffer + sizeof buffer) {
- std::snprintf(q + result.length, sizeof buffer, "e%d", expo);
+ std::snprintf(q + result.length, sizeof buffer - (q + result.length - buffer), "e%d", expo);
}
const char *p{q};
auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155224.540121.patch
Type: text/x-patch
Size: 1129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230713/07f424db/attachment.bin>
More information about the flang-commits
mailing list