diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeVersion.cmake | 4 | ||||
-rw-r--r-- | Source/cmLinkedTree.h | 6 | ||||
-rw-r--r-- | Source/cmSetCommand.cxx | 14 | ||||
-rw-r--r-- | Source/cmTryRunCommand.cxx | 9 | ||||
-rw-r--r-- | Source/cmUnsetCommand.cxx | 13 | ||||
-rw-r--r-- | Source/kwsys/CommandLineArguments.cxx | 5 | ||||
-rw-r--r-- | Source/kwsys/ProcessUNIX.c | 20 | ||||
-rw-r--r-- | Source/kwsys/ProcessWin32.c | 15 | ||||
-rw-r--r-- | Source/kwsys/SystemInformation.cxx | 2 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 17 | ||||
-rw-r--r-- | Source/kwsys/testEncoding.cxx | 5 | ||||
-rw-r--r-- | Source/kwsys/testProcess.c | 4 | ||||
-rw-r--r-- | Source/kwsys/testSystemTools.cxx | 10 |
13 files changed, 53 insertions, 71 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 9eaee8a..4e833a3 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 10) -set(CMake_VERSION_PATCH 0) -set(CMake_VERSION_RC 2) +set(CMake_VERSION_PATCH 20171012) +#set(CMake_VERSION_RC 1) diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h index 8865e23..975f052 100644 --- a/Source/cmLinkedTree.h +++ b/Source/cmLinkedTree.h @@ -137,7 +137,7 @@ public: iterator Push(iterator it) { return Push_impl(it, T()); } - iterator Push(iterator it, T t) { return Push_impl(it, t); } + iterator Push(iterator it, T t) { return Push_impl(it, std::move(t)); } bool IsLast(iterator it) { return it.Position == this->Data.size(); } @@ -177,12 +177,12 @@ private: T* GetPointer(PositionType pos) { return &this->Data[pos]; } - iterator Push_impl(iterator it, T t) + iterator Push_impl(iterator it, T&& t) { assert(this->UpPositions.size() == this->Data.size()); assert(it.Position <= this->UpPositions.size()); this->UpPositions.push_back(it.Position); - this->Data.push_back(t); + this->Data.push_back(std::move(t)); return iterator(this, this->UpPositions.size()); } diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index b32cda3..985aac8 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -2,8 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmSetCommand.h" -#include <string.h> - #include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmState.h" @@ -22,19 +20,15 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args, } // watch for ENV signatures - const char* variable = args[0].c_str(); // VAR is always first - if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) { + auto const& variable = args[0]; // VAR is always first + if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 5) { // what is the variable name - char* varName = new char[strlen(variable)]; - strncpy(varName, variable + 4, strlen(variable) - 5); - varName[strlen(variable) - 5] = '\0'; - std::string putEnvArg = varName; - putEnvArg += "="; + auto const& varName = variable.substr(4, variable.size() - 5); + std::string putEnvArg = varName + "="; // what is the current value if any std::string currValue; const bool currValueSet = cmSystemTools::GetEnv(varName, currValue); - delete[] varName; // will it be set to something, then set it if (args.size() > 1 && !args[1].empty()) { diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index dcaa493..932b976 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -4,7 +4,6 @@ #include "cmsys/FStream.hxx" #include <stdio.h> -#include <string.h> #include "cmMakefile.h" #include "cmState.h" @@ -191,13 +190,15 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, finalCommand.c_str(), out, out, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, timeout); // set the run var - char retChar[1000]; + char retChar[16]; + const char* retStr; if (worked) { sprintf(retChar, "%i", retVal); + retStr = retChar; } else { - strcpy(retChar, "FAILED_TO_RUN"); + retStr = "FAILED_TO_RUN"; } - this->Makefile->AddCacheDefinition(this->RunResultVariable, retChar, + this->Makefile->AddCacheDefinition(this->RunResultVariable, retStr, "Result of TRY_RUN", cmStateEnums::INTERNAL); } diff --git a/Source/cmUnsetCommand.cxx b/Source/cmUnsetCommand.cxx index 18bbdd7..cfaa1fd2 100644 --- a/Source/cmUnsetCommand.cxx +++ b/Source/cmUnsetCommand.cxx @@ -2,8 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmUnsetCommand.h" -#include <string.h> - #include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmSystemTools.h" @@ -19,19 +17,16 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args, return false; } - const char* variable = args[0].c_str(); + auto const& variable = args[0]; // unset(ENV{VAR}) - if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) { + if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 5) { // what is the variable name - char* envVarName = new char[strlen(variable)]; - strncpy(envVarName, variable + 4, strlen(variable) - 5); - envVarName[strlen(variable) - 5] = '\0'; + auto const& envVarName = variable.substr(4, variable.size() - 5); #ifdef CMAKE_BUILD_WITH_CMAKE - cmSystemTools::UnsetEnv(envVarName); + cmSystemTools::UnsetEnv(envVarName.c_str()); #endif - delete[] envVarName; return true; } // unset(VAR) diff --git a/Source/kwsys/CommandLineArguments.cxx b/Source/kwsys/CommandLineArguments.cxx index 5613bd7..5498377 100644 --- a/Source/kwsys/CommandLineArguments.cxx +++ b/Source/kwsys/CommandLineArguments.cxx @@ -649,10 +649,7 @@ void CommandLineArguments::PopulateVariable(double* variable, void CommandLineArguments::PopulateVariable(char** variable, const std::string& value) { - if (*variable) { - delete[] * variable; - *variable = 0; - } + delete[] * variable; *variable = new char[value.size() + 1]; strcpy(*variable, value.c_str()); } diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 3b32ca7..1431f30 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -359,9 +359,7 @@ void kwsysProcess_Delete(kwsysProcess* cp) kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDIN, 0); kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDOUT, 0); kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDERR, 0); - if (cp->CommandExitCodes) { - free(cp->CommandExitCodes); - } + free(cp->CommandExitCodes); free(cp->ProcessResults); free(cp); } @@ -498,11 +496,10 @@ int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir) cp->WorkingDirectory = 0; } if (dir) { - cp->WorkingDirectory = (char*)malloc(strlen(dir) + 1); + cp->WorkingDirectory = strdup(dir); if (!cp->WorkingDirectory) { return 0; } - strcpy(cp->WorkingDirectory, dir); } return 1; } @@ -531,11 +528,10 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int prPipe, const char* file) *pfile = 0; } if (file) { - *pfile = (char*)malloc(strlen(file) + 1); + *pfile = strdup(file); if (!*pfile) { return 0; } - strcpy(*pfile, file); } /* If we are redirecting the pipe, do not share it or use a native @@ -1514,9 +1510,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp) oldForkPIDs = cp->ForkPIDs; cp->ForkPIDs = (volatile pid_t*)malloc(sizeof(volatile pid_t) * (size_t)(cp->NumberOfCommands)); - if (oldForkPIDs) { - kwsysProcessVolatileFree(oldForkPIDs); - } + kwsysProcessVolatileFree(oldForkPIDs); if (!cp->ForkPIDs) { return 0; } @@ -1524,9 +1518,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp) cp->ForkPIDs[i] = 0; /* can't use memset due to volatile */ } - if (cp->CommandExitCodes) { - free(cp->CommandExitCodes); - } + free(cp->CommandExitCodes); cp->CommandExitCodes = (int*)malloc(sizeof(int) * (size_t)(cp->NumberOfCommands)); if (!cp->CommandExitCodes) { @@ -1938,6 +1930,7 @@ static int kwsysProcessSetupOutputPipeFile(int* p, const char* name) /* Set close-on-exec flag on the pipe's end. */ if (fcntl(fout, F_SETFD, FD_CLOEXEC) < 0) { + close(fout); return 0; } @@ -2290,6 +2283,7 @@ static void kwsysProcessChildErrorExit(int errorPipe) char buffer[KWSYSPE_PIPE_BUFFER_SIZE]; kwsysProcess_ssize_t result; strncpy(buffer, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE); + buffer[KWSYSPE_PIPE_BUFFER_SIZE - 1] = '\0'; /* Report the error to the parent through the special pipe. */ result = write(errorPipe, buffer, strlen(buffer)); diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c index 5183e3d..945fa28 100644 --- a/Source/kwsys/ProcessWin32.c +++ b/Source/kwsys/ProcessWin32.c @@ -523,9 +523,7 @@ void kwsysProcess_Delete(kwsysProcess* cp) kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDIN, 0); kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDOUT, 0); kwsysProcess_SetPipeFile(cp, kwsysProcess_Pipe_STDERR, 0); - if (cp->CommandExitCodes) { - free(cp->CommandExitCodes); - } + free(cp->CommandExitCodes); free(cp->ProcessResults); free(cp); } @@ -713,11 +711,10 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe, const char* file) *pfile = 0; } if (file) { - *pfile = (char*)malloc(strlen(file) + 1); + *pfile = strdup(file); if (!*pfile) { return 0; } - strcpy(*pfile, file); } /* If we are redirecting the pipe, do not share it or use a native @@ -1607,9 +1604,7 @@ int kwsysProcessInitialize(kwsysProcess* cp) } ZeroMemory(cp->ProcessInformation, sizeof(PROCESS_INFORMATION) * cp->NumberOfCommands); - if (cp->CommandExitCodes) { - free(cp->CommandExitCodes); - } + free(cp->CommandExitCodes); cp->CommandExitCodes = (DWORD*)malloc(sizeof(DWORD) * cp->NumberOfCommands); if (!cp->CommandExitCodes) { return 0; @@ -2362,9 +2357,7 @@ static int kwsysProcess_List__New_NT4(kwsysProcess_List* self) static void kwsysProcess_List__Delete_NT4(kwsysProcess_List* self) { /* Free the process information buffer. */ - if (self->Buffer) { - free(self->Buffer); - } + free(self->Buffer); } static int kwsysProcess_List__Update_NT4(kwsysProcess_List* self) diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 86fdccd..366fe30 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -1346,7 +1346,7 @@ std::string SymbolProperties::GetBinary() const std::string binary; char buf[1024] = { '\0' }; ssize_t ll = 0; - if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0) { + if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0 && ll < 1024) { buf[ll] = '\0'; binary = buf; } else { diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index ecfa331..a24a326 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -20,6 +20,7 @@ #include KWSYS_HEADER(SystemTools.hxx) #include KWSYS_HEADER(Directory.hxx) #include KWSYS_HEADER(FStream.hxx) +#include KWSYS_HEADER(Encoding.h) #include KWSYS_HEADER(Encoding.hxx) #include <fstream> @@ -227,13 +228,17 @@ inline const char* Getcwd(char* buf, unsigned int len) { std::vector<wchar_t> w_buf(len); if (_wgetcwd(&w_buf[0], len)) { - // make sure the drive letter is capital - if (wcslen(&w_buf[0]) > 1 && w_buf[1] == L':') { - w_buf[0] = towupper(w_buf[0]); + size_t nlen = kwsysEncoding_wcstombs(buf, &w_buf[0], len); + if (nlen == static_cast<size_t>(-1)) { + return 0; + } + if (nlen < len) { + // make sure the drive letter is capital + if (nlen > 1 && buf[1] == ':') { + buf[0] = toupper(buf[0]); + } + return buf; } - std::string tmp = KWSYS_NAMESPACE::Encoding::ToNarrow(&w_buf[0]); - strcpy(buf, tmp.c_str()); - return buf; } return 0; } diff --git a/Source/kwsys/testEncoding.cxx b/Source/kwsys/testEncoding.cxx index 2c5ef46..2742fe4 100644 --- a/Source/kwsys/testEncoding.cxx +++ b/Source/kwsys/testEncoding.cxx @@ -75,6 +75,10 @@ static int testRobustEncoding() // test that the conversion functions handle invalid // unicode correctly/gracefully + // we manipulate the format flags of stdout, remember + // the original state here to restore before return + std::ios::fmtflags const& flags = std::cout.flags(); + int ret = 0; char cstr[] = { (char)-1, 0 }; // this conversion could fail @@ -120,6 +124,7 @@ static int testRobustEncoding() ret++; } + std::cout.flags(flags); return ret; } diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c index 092dd03..cd817d9 100644 --- a/Source/kwsys/testProcess.c +++ b/Source/kwsys/testProcess.c @@ -687,9 +687,7 @@ int main(int argc, const char* argv[]) fflush(stdout); fflush(stderr); #if defined(_WIN32) - if (argv0) { - free(argv0); - } + free(argv0); #endif return r; } else if (argc > 2 && strcmp(argv[1], "0") == 0) { diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index 768eb4d..3b694c9 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -254,22 +254,22 @@ static bool CheckFileOperations() } // should work, was created as new file before if (!kwsys::SystemTools::FileExists(testNewFile)) { - std::cerr << "Problem with FileExists for: " << testNewDir << std::endl; + std::cerr << "Problem with FileExists for: " << testNewFile << std::endl; res = false; } if (!kwsys::SystemTools::FileExists(testNewFile.c_str())) { - std::cerr << "Problem with FileExists as C string for: " << testNewDir + std::cerr << "Problem with FileExists as C string for: " << testNewFile << std::endl; res = false; } if (!kwsys::SystemTools::FileExists(testNewFile, true)) { - std::cerr << "Problem with FileExists as file for: " << testNewDir + std::cerr << "Problem with FileExists as file for: " << testNewFile << std::endl; res = false; } if (!kwsys::SystemTools::FileExists(testNewFile.c_str(), true)) { std::cerr << "Problem with FileExists as C string and file for: " - << testNewDir << std::endl; + << testNewFile << std::endl; res = false; } @@ -285,7 +285,7 @@ static bool CheckFileOperations() } // should work, was created as new file before if (!kwsys::SystemTools::PathExists(testNewFile)) { - std::cerr << "Problem with PathExists for: " << testNewDir << std::endl; + std::cerr << "Problem with PathExists for: " << testNewFile << std::endl; res = false; } |