summaryrefslogtreecommitdiff
path: root/Source/CTest/cmCTestMemCheckHandler.cxx
diff options
context:
space:
mode:
authorWouter Klouwen <wouter.klouwen@youview.com>2017-12-12 21:59:43 +0000
committerBrad King <brad.king@kitware.com>2018-01-23 10:05:12 -0500
commitff62b00522d1ddaeb88be241ab4a022f935b5c00 (patch)
tree5144559ff41c2374fd01637b0326fb18eed2c1eb /Source/CTest/cmCTestMemCheckHandler.cxx
parent695951bc46fa4bc4eaf686c4ee6dce24c579bc45 (diff)
downloadcmake-ff62b00522d1ddaeb88be241ab4a022f935b5c00.tar.gz
CTest: add safe conversion from cmDuration to integer types
A problem area by recent refactoring of time to std::chrono has been the unsafe conversion from duration<double> to std::chrono::seconds, which is of an unspecified integer type. This commit adds a template function that for a given type provides a safe conversion, effectively clamping a duration<double> into what fits safely in that type. A specialisation for int and unsigned int are provided. It changes the protential problem areas to use this safe function.
Diffstat (limited to 'Source/CTest/cmCTestMemCheckHandler.cxx')
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.cxx23
1 files changed, 11 insertions, 12 deletions
diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx
index 6b6c337ecf..c3fbc0da29 100644
--- a/Source/CTest/cmCTestMemCheckHandler.cxx
+++ b/Source/CTest/cmCTestMemCheckHandler.cxx
@@ -3,6 +3,7 @@
#include "cmCTestMemCheckHandler.h"
#include "cmCTest.h"
+#include "cmDuration.h"
#include "cmSystemTools.h"
#include "cmXMLParser.h"
#include "cmXMLWriter.h"
@@ -920,12 +921,11 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
break; // stop the copy of output if we are full
}
}
- cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
- << std::chrono::duration_cast<std::chrono::seconds>(
- std::chrono::steady_clock::now() - sttime)
- .count()
- << "s)" << std::endl,
- this->Quiet);
+ cmCTestOptionalLog(
+ this->CTest, DEBUG, "End test (elapsed: "
+ << cmDurationTo<unsigned int>(std::chrono::steady_clock::now() - sttime)
+ << "s)" << std::endl,
+ this->Quiet);
log = ostr.str();
this->DefectCount += defects;
return defects == 0;
@@ -966,12 +966,11 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
results[err]++;
defects++;
}
- cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
- << std::chrono::duration_cast<std::chrono::seconds>(
- std::chrono::steady_clock::now() - sttime)
- .count()
- << "s)" << std::endl,
- this->Quiet);
+ cmCTestOptionalLog(
+ this->CTest, DEBUG, "End test (elapsed: "
+ << cmDurationTo<unsigned int>(std::chrono::steady_clock::now() - sttime)
+ << "s)" << std::endl,
+ this->Quiet);
if (defects) {
// only put the output of Bounds Checker if there were
// errors or leaks detected