summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-10-27 13:23:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-10-27 13:23:17 (GMT)
commit9bb7982a15e51b0336e58d4cafc20529ec50550d (patch)
tree5cc5b6744ac6f8da254487002a5a9a7cd832ba80 /Source/CTest
parentede11598ba16841c7652160ba8dd755c259bc122 (diff)
parentb7e9cd05cd07605d01a50522f65347aa23d2647e (diff)
downloadCMake-9bb7982a15e51b0336e58d4cafc20529ec50550d.zip
CMake-9bb7982a15e51b0336e58d4cafc20529ec50550d.tar.gz
CMake-9bb7982a15e51b0336e58d4cafc20529ec50550d.tar.bz2
Merge topic 'purge-sprintf'
b7e9cd05cd Replace the only non-standard _snprintf with snprintf 5ba6e8ac59 Source: Replace most calls to sprintf with snprintf Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6649
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestCoverageHandler.cxx6
-rw-r--r--Source/CTest/cmCTestGIT.cxx9
-rw-r--r--Source/CTest/cmCTestRunTest.cxx10
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx2
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx4
-rw-r--r--Source/CTest/cmCTestVC.cxx5
-rw-r--r--Source/CTest/cmProcess.cxx2
7 files changed, 22 insertions, 16 deletions
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
index b16d4d0..4c738c3 100644
--- a/Source/CTest/cmCTestCoverageHandler.cxx
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -147,7 +147,8 @@ bool cmCTestCoverageHandler::StartCoverageLogFile(
cmGeneratedFileStream& covLogFile, int logFileCount)
{
char covLogFilename[1024];
- sprintf(covLogFilename, "CoverageLog-%d", logFileCount);
+ snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d",
+ logFileCount);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Open file: " << covLogFilename << std::endl,
this->Quiet);
@@ -164,7 +165,8 @@ void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr,
int logFileCount)
{
char covLogFilename[1024];
- sprintf(covLogFilename, "CoverageLog-%d.xml", logFileCount);
+ snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d.xml",
+ logFileCount);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Close file: " << covLogFilename << std::endl,
this->Quiet);
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx
index d85edcc..da94754 100644
--- a/Source/CTest/cmCTestGIT.cxx
+++ b/Source/CTest/cmCTestGIT.cxx
@@ -582,16 +582,17 @@ private:
time_t seconds = static_cast<time_t>(person.Time);
struct tm* t = gmtime(&seconds);
char dt[1024];
- sprintf(dt, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900,
- t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+ snprintf(dt, sizeof(dt), "%04d-%02d-%02d %02d:%02d:%02d",
+ t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour,
+ t->tm_min, t->tm_sec);
std::string out = dt;
// Add the time-zone field "+zone" or "-zone".
char tz[32];
if (person.TimeZone >= 0) {
- sprintf(tz, " +%04ld", person.TimeZone);
+ snprintf(tz, sizeof(tz), " +%04ld", person.TimeZone);
} else {
- sprintf(tz, " -%04ld", -person.TimeZone);
+ snprintf(tz, sizeof(tz), " -%04ld", -person.TimeZone);
}
out += tz;
return out;
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 2d1562a..f76fc3e 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -229,7 +229,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
char buf[1024];
- sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count());
+ snprintf(buf, sizeof(buf), "%6.2f sec",
+ this->TestProcess->GetTotalTime().count());
outputStream << buf << "\n";
bool passedOrSkipped = passed || skipped;
@@ -294,9 +295,10 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
ttime -= minutes;
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(ttime);
char buffer[100];
- sprintf(buffer, "%02d:%02d:%02d", static_cast<unsigned>(hours.count()),
- static_cast<unsigned>(minutes.count()),
- static_cast<unsigned>(seconds.count()));
+ snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d",
+ static_cast<unsigned>(hours.count()),
+ static_cast<unsigned>(minutes.count()),
+ static_cast<unsigned>(seconds.count()));
*this->TestHandler->LogFile
<< "----------------------------------------------------------"
<< std::endl;
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index f685f66..84087c5 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -411,7 +411,7 @@ int cmCTestScriptHandler::ExtractVariables()
char updateVar[40];
int i;
for (i = 1; i < 10; ++i) {
- sprintf(updateVar, "CTEST_EXTRA_UPDATES_%i", i);
+ snprintf(updateVar, sizeof(updateVar), "CTEST_EXTRA_UPDATES_%i", i);
cmValue updateVal = this->Makefile->GetDefinition(updateVar);
if (updateVal) {
if (this->UpdateCmd.empty()) {
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 34088d2..02db0c6 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -623,7 +623,7 @@ void cmCTestTestHandler::LogTestSummary(const std::vector<std::string>& passed,
this->PrintLabelOrSubprojectSummary(false);
}
char realBuf[1024];
- sprintf(realBuf, "%6.2f sec", durationInSecs.count());
+ snprintf(realBuf, sizeof(realBuf), "%6.2f sec", durationInSecs.count());
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\nTotal Test time (real) = " << realBuf << "\n",
this->Quiet);
@@ -784,7 +784,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
label.resize(maxlen + 3, ' ');
char buf[1024];
- sprintf(buf, "%6.2f sec*proc", labelTimes[i]);
+ snprintf(buf, sizeof(buf), "%6.2f sec*proc", labelTimes[i]);
std::ostringstream labelCountStr;
labelCountStr << "(" << labelCounts[i] << " test";
diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx
index 423b506..9ba6456 100644
--- a/Source/CTest/cmCTestVC.cxx
+++ b/Source/CTest/cmCTestVC.cxx
@@ -123,8 +123,9 @@ std::string cmCTestVC::GetNightlyTime()
this->CTest->GetCTestConfiguration("NightlyStartTime"),
this->CTest->GetTomorrowTag());
char current_time[1024];
- sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900,
- t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+ snprintf(current_time, sizeof(current_time), "%04d-%02d-%02d %02d:%02d:%02d",
+ t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
+ t->tm_sec);
return std::string(current_time);
}
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
index 16bca01..e14a4e1 100644
--- a/Source/CTest/cmProcess.cxx
+++ b/Source/CTest/cmProcess.cxx
@@ -511,7 +511,7 @@ std::string cmProcess::GetExitExceptionString() const
default:
char buf[1024];
const char* fmt = "Exit code 0x%" KWIML_INT_PRIx64 "\n";
- _snprintf(buf, 1024, fmt, this->ExitValue);
+ snprintf(buf, sizeof(buf), fmt, this->ExitValue);
exception_str.assign(buf);
}
#else