Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-05-30 16:28:23 +0200
committerMartin Hořeňovský2021-05-31 08:41:26 +0200
commit0e2895934cf778f3bd7e84b3df10dac81d4ef7e3 (patch)
treee6caf67960051a7f4efd8b3ccad4b2940cc47650
parenta01073d87105371f4465e243fde9ae719d52f5d1 (diff)
downloadcatch3-0e2895934cf778f3bd7e84b3df10dac81d4ef7e3.tar.gz
Use precomputed string sizes when constructing std::strings
-rw-r--r--src/catch2/reporters/catch_reporter_combined_tu.cpp8
-rw-r--r--src/catch2/reporters/catch_reporter_junit.cpp2
2 files changed, 6 insertions, 4 deletions
diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp
index a05b4998..42974249 100644
--- a/src/catch2/reporters/catch_reporter_combined_tu.cpp
+++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp
@@ -69,11 +69,13 @@ namespace Catch {
// Save previous errno, to prevent sprintf from overwriting it
ErrnoGuard guard;
#ifdef _MSC_VER
- sprintf_s( buffer, "%.3f", duration );
+ size_t printedLength = static_cast<size_t>(
+ sprintf_s( buffer, "%.3f", duration ) );
#else
- std::snprintf( buffer, maxDoubleSize, "%.3f", duration );
+ size_t printedLength = static_cast<size_t>(
+ std::snprintf( buffer, maxDoubleSize, "%.3f", duration ) );
#endif
- return std::string( buffer );
+ return std::string( buffer, printedLength );
}
bool shouldShowDuration( IConfig const& config, double duration ) {
diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp
index c5d0929c..7570d9ea 100644
--- a/src/catch2/reporters/catch_reporter_junit.cpp
+++ b/src/catch2/reporters/catch_reporter_junit.cpp
@@ -38,7 +38,7 @@ namespace Catch {
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
- return std::string(timeStamp);
+ return std::string(timeStamp, timeStampSize - 1);
}
std::string fileNameTag(std::vector<Tag> const& tags) {