diff options
| author | Martin Hořeňovský | 2021-05-30 16:28:23 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-05-31 08:41:26 +0200 |
| commit | 0e2895934cf778f3bd7e84b3df10dac81d4ef7e3 (patch) | |
| tree | e6caf67960051a7f4efd8b3ccad4b2940cc47650 /src | |
| parent | a01073d87105371f4465e243fde9ae719d52f5d1 (diff) | |
| download | catch3-0e2895934cf778f3bd7e84b3df10dac81d4ef7e3.tar.gz | |
Use precomputed string sizes when constructing std::strings
Diffstat (limited to 'src')
| -rw-r--r-- | src/catch2/reporters/catch_reporter_combined_tu.cpp | 8 | ||||
| -rw-r--r-- | src/catch2/reporters/catch_reporter_junit.cpp | 2 |
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) { |