From 3674f6a47000db2b519a44062b8ce46db4f12691 Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Wed, 13 May 2020 06:38:50 -0400 Subject: KWSys 2020-05-13 (d4da6980) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit d4da69800d9103a7d3654f9428386a914ba280f2 (master). Upstream Shortlog ----------------- Sean McBride (5): c58d4b47 SystemTools: On Windows, strip 'e' from Fopen mode cb541c31 Auto-fixed various clang-tidy warnings 2c179921 Applied clang-tidy modernize-deprecated-headers 775296c8 Applied clang-tidy bugprone-suspicious-string-compare fixes a19f0ac6 Fixed clang -Wstrict-prototypes warning --- CommandLineArguments.cxx | 6 +++--- EncodingCXX.cxx | 4 ++-- Glob.cxx | 6 +++--- RegularExpression.cxx | 7 +++---- SystemInformation.cxx | 26 +++++++++++++------------- SystemTools.cxx | 37 +++++++++++++++++++++---------------- SystemTools.hxx.in | 3 ++- testCommandLineArguments.cxx | 4 ++-- testCommandLineArguments1.cxx | 8 +++----- testDynload.c | 2 +- testEncoding.cxx | 8 ++++---- testFStream.cxx | 2 +- testSystemTools.cxx | 16 ++++++++-------- 13 files changed, 66 insertions(+), 63 deletions(-) diff --git a/CommandLineArguments.cxx b/CommandLineArguments.cxx index a2ed874..e45db36 100644 --- a/CommandLineArguments.cxx +++ b/CommandLineArguments.cxx @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #ifdef _MSC_VER # pragma warning(disable : 4786) diff --git a/EncodingCXX.cxx b/EncodingCXX.cxx index 5cad934..c68c73c 100644 --- a/EncodingCXX.cxx +++ b/EncodingCXX.cxx @@ -17,8 +17,8 @@ # include "Encoding.hxx.in" #endif -#include -#include +#include +#include #include #ifdef _MSC_VER diff --git a/Glob.cxx b/Glob.cxx index 8e30f92..fad6ee1 100644 --- a/Glob.cxx +++ b/Glob.cxx @@ -23,9 +23,9 @@ #include #include -#include -#include -#include +#include +#include +#include namespace KWSYS_NAMESPACE { #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__) // On Windows and Apple, no difference between lower and upper case diff --git a/RegularExpression.cxx b/RegularExpression.cxx index 5e6f8da..4f74eba 100644 --- a/RegularExpression.cxx +++ b/RegularExpression.cxx @@ -28,8 +28,8 @@ # include "RegularExpression.hxx.in" #endif -#include -#include +#include +#include namespace KWSYS_NAMESPACE { @@ -367,8 +367,7 @@ bool RegularExpression::compile(const char* exp) // Allocate space. //#ifndef _WIN32 - if (this->program != nullptr) - delete[] this->program; + delete[] this->program; //#endif this->program = new char[comp.regsize]; this->progsize = static_cast(comp.regsize); diff --git a/SystemInformation.cxx b/SystemInformation.cxx index ba9fa67..c565823 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -64,9 +64,9 @@ typedef int siginfo_t; #else # include -# include // extern int errno; +# include // extern int errno; +# include # include -# include # include // getrlimit # include # include // int uname(struct utsname *buf); @@ -163,11 +163,11 @@ typedef struct rlimit ResourceLimitType; # undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP #endif -#include // int isdigit(int c); +#include // int isdigit(int c); +#include +#include +#include #include -#include -#include -#include #if defined(KWSYS_USE_LONG_LONG) # if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) @@ -1366,7 +1366,7 @@ std::string SymbolProperties::GetFileName(const std::string& path) const { std::string file(path); if (!this->ReportPath) { - size_t at = file.rfind("/"); + size_t at = file.rfind('/'); if (at != std::string::npos) { file.erase(0, at + 1); } @@ -3387,8 +3387,8 @@ std::string SystemInformationImplementation::ExtractValueFromCpuInfoFile( size_t pos = buffer.find(word, init); if (pos != std::string::npos) { this->CurrentPositionInFile = pos; - pos = buffer.find(":", pos); - size_t pos2 = buffer.find("\n", pos); + pos = buffer.find(':', pos); + size_t pos2 = buffer.find('\n', pos); if (pos != std::string::npos && pos2 != std::string::npos) { // It may happen that the beginning matches, but this is still not the // requested key. @@ -3937,7 +3937,7 @@ std::string SystemInformationImplementation::GetProgramStack(int firstFrame, int wholePath) { std::ostringstream oss; - std::string programStack = ""; + std::string programStack; #ifdef KWSYS_SYSTEMINFORMATION_HAS_DBGHELP (void)wholePath; @@ -4688,7 +4688,7 @@ std::string SystemInformationImplementation::ExtractValueFromSysCtl( size_t pos = this->SysCtlBuffer.find(word); if (pos != std::string::npos) { pos = this->SysCtlBuffer.find(": ", pos); - size_t pos2 = this->SysCtlBuffer.find("\n", pos); + size_t pos2 = this->SysCtlBuffer.find('\n', pos); if (pos != std::string::npos && pos2 != std::string::npos) { return this->SysCtlBuffer.substr(pos + 2, pos2 - pos - 2); } @@ -5500,13 +5500,13 @@ void SystemInformationImplementation::TrimNewline(std::string& output) { // remove \r std::string::size_type pos = 0; - while ((pos = output.find("\r", pos)) != std::string::npos) { + while ((pos = output.find('\r', pos)) != std::string::npos) { output.erase(pos); } // remove \n pos = 0; - while ((pos = output.find("\n", pos)) != std::string::npos) { + while ((pos = output.find('\n', pos)) != std::string::npos) { output.erase(pos); } } diff --git a/SystemTools.cxx b/SystemTools.cxx index 3a6ceec..a6d210f 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -24,6 +24,7 @@ #include KWSYS_HEADER(Encoding.h) #include KWSYS_HEADER(Encoding.hxx) +#include #include #include #include @@ -49,15 +50,15 @@ # pragma set woff 1375 /* base class destructor not virtual */ #endif -#include -#include +#include +#include #ifdef __QNX__ # include /* for malloc/free on QNX */ #endif -#include -#include -#include -#include +#include +#include +#include +#include #if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__) # include /* for strcasecmp */ @@ -69,7 +70,7 @@ // support for realpath call #ifndef _WIN32 -# include +# include # include # include # include @@ -80,7 +81,7 @@ # include # include # endif -# include /* sigprocmask */ +# include /* sigprocmask */ #endif #ifdef __linux @@ -892,8 +893,12 @@ const char* SystemTools::GetExecutableExtension() FILE* SystemTools::Fopen(const std::string& file, const char* mode) { #ifdef _WIN32 + // Remove any 'e', which is supported on UNIX, but not Windows. + std::wstring trimmedMode = Encoding::ToWide(mode); + trimmedMode.erase(std::remove(trimmedMode.begin(), trimmedMode.end(), L'e'), + trimmedMode.end()); return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(), - Encoding::ToWide(mode).c_str()); + trimmedMode.c_str()); #else return fopen(file.c_str(), mode); #endif @@ -2113,7 +2118,7 @@ std::string SystemTools::ConvertToUnixOutputPath(const std::string& path) ret.erase(pos, 1); } // escape spaces and () in the path - if (ret.find_first_of(" ") != std::string::npos) { + if (ret.find_first_of(' ') != std::string::npos) { std::string result; char lastch = 1; for (const char* ch = ret.c_str(); *ch != '\0'; ++ch) { @@ -2511,8 +2516,8 @@ bool SystemTools::CopyADirectory(const std::string& source, return false; } for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { - if (strcmp(dir.GetFile(static_cast(fileNum)), ".") && - strcmp(dir.GetFile(static_cast(fileNum)), "..")) { + if (strcmp(dir.GetFile(static_cast(fileNum)), ".") != 0 && + strcmp(dir.GetFile(static_cast(fileNum)), "..") != 0) { std::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast(fileNum)); @@ -2674,8 +2679,8 @@ bool SystemTools::RemoveADirectory(const std::string& source) dir.Load(source); size_t fileNum; for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { - if (strcmp(dir.GetFile(static_cast(fileNum)), ".") && - strcmp(dir.GetFile(static_cast(fileNum)), "..")) { + if (strcmp(dir.GetFile(static_cast(fileNum)), ".") != 0 && + strcmp(dir.GetFile(static_cast(fileNum)), "..") != 0) { std::string fullPath = source; fullPath += "/"; fullPath += dir.GetFile(static_cast(fileNum)); @@ -3153,7 +3158,7 @@ bool SystemTools::SplitProgramPath(const std::string& in_name, SystemTools::ConvertToUnixSlashes(dir); if (!SystemTools::FileIsDirectory(dir)) { - std::string::size_type slashPos = dir.rfind("/"); + std::string::size_type slashPos = dir.rfind('/'); if (slashPos != std::string::npos) { file = dir.substr(slashPos + 1); dir.resize(slashPos); @@ -3711,7 +3716,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename) std::string fn = filename; SystemTools::ConvertToUnixSlashes(fn); - std::string::size_type slash_pos = fn.rfind("/"); + std::string::size_type slash_pos = fn.rfind('/'); if (slash_pos == 0) { return "/"; } diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index cd7b728..ae08e57 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -549,7 +549,8 @@ public: */ /** - * Open a file considering unicode. + * Open a file considering unicode. On Windows, if 'e' is present in + * mode it is first discarded. */ static FILE* Fopen(const std::string& file, const char* mode); diff --git a/testCommandLineArguments.cxx b/testCommandLineArguments.cxx index 79ebe1a..0786751 100644 --- a/testCommandLineArguments.cxx +++ b/testCommandLineArguments.cxx @@ -12,8 +12,8 @@ #include #include -#include /* size_t */ -#include /* strcmp */ +#include /* size_t */ +#include /* strcmp */ static void* random_ptr = reinterpret_cast(0x123); diff --git a/testCommandLineArguments1.cxx b/testCommandLineArguments1.cxx index cbc3002..2f6b735 100644 --- a/testCommandLineArguments1.cxx +++ b/testCommandLineArguments1.cxx @@ -12,8 +12,8 @@ #include #include -#include /* assert */ -#include /* strcmp */ +#include /* assert */ +#include /* strcmp */ int testCommandLineArguments1(int argc, char* argv[]) { @@ -51,9 +51,7 @@ int testCommandLineArguments1(int argc, char* argv[]) std::cout << "Value of N: " << n << std::endl; std::cout << "Value of M: " << m << std::endl; std::cout << "Value of P: " << p << std::endl; - if (m) { - delete[] m; - } + delete[] m; char** newArgv = nullptr; int newArgc = 0; diff --git a/testDynload.c b/testDynload.c index c49f747..33a431e 100644 --- a/testDynload.c +++ b/testDynload.c @@ -8,6 +8,6 @@ DL_EXPORT int TestDynamicLoaderData = 0; -DL_EXPORT void TestDynamicLoaderSymbolPointer() +DL_EXPORT void TestDynamicLoaderSymbolPointer(void) { } diff --git a/testEncoding.cxx b/testEncoding.cxx index d672aed..ee93e8d 100644 --- a/testEncoding.cxx +++ b/testEncoding.cxx @@ -10,10 +10,10 @@ #include KWSYS_HEADER(Encoding.h) #include +#include +#include +#include #include -#include -#include -#include // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. @@ -59,7 +59,7 @@ static int testHelloWorldEncoding() std::string str2 = kwsys::Encoding::ToNarrow(wstr); wchar_t* c_wstr = kwsysEncoding_DupToWide(str.c_str()); char* c_str2 = kwsysEncoding_DupToNarrow(c_wstr); - if (!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str()))) { + if (!wstr.empty() && (str != str2 || strcmp(c_str2, str.c_str()) != 0)) { std::cout << "converted string was different: " << str2 << std::endl; std::cout << "converted string was different: " << c_str2 << std::endl; ret++; diff --git a/testFStream.cxx b/testFStream.cxx index 5009e98..5762378 100644 --- a/testFStream.cxx +++ b/testFStream.cxx @@ -7,7 +7,7 @@ #endif #include KWSYS_HEADER(FStream.hxx) -#include +#include #ifdef __BORLANDC__ # include /* memcmp */ #endif diff --git a/testSystemTools.cxx b/testSystemTools.cxx index 8909b49..ff8e2b2 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -20,10 +20,10 @@ // left on disk. #include +#include /* free */ +#include /* strcmp */ #include #include -#include /* free */ -#include /* strcmp */ #if defined(_WIN32) && !defined(__CYGWIN__) # include /* _umask (MSVC) / umask (Borland) */ # ifdef _MSC_VER @@ -507,7 +507,7 @@ static bool CheckStringOperations() char* cres = kwsys::SystemTools::AppendStrings("Mary Had A", " Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with AppendStrings " << "\"Mary Had A\" \" Little Lamb.\"" << std::endl; res = false; @@ -515,7 +515,7 @@ static bool CheckStringOperations() delete[] cres; cres = kwsys::SystemTools::AppendStrings("Mary Had", " A ", "Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with AppendStrings " << "\"Mary Had\" \" A \" \"Little Lamb.\"" << std::endl; res = false; @@ -529,7 +529,7 @@ static bool CheckStringOperations() } cres = kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.", "aeiou"); - if (strcmp(cres, "Mry Hd A Lttl Lmb.")) { + if (strcmp(cres, "Mry Hd A Lttl Lmb.") != 0) { std::cerr << "Problem with RemoveChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -537,7 +537,7 @@ static bool CheckStringOperations() delete[] cres; cres = kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb."); - if (strcmp(cres, "A")) { + if (strcmp(cres, "A") != 0) { std::cerr << "Problem with RemoveCharsButUpperHex " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -546,7 +546,7 @@ static bool CheckStringOperations() char* cres2 = strdup("Mary Had A Little Lamb."); kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X'); - if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) { + if (strcmp(cres2, "MXry HXd A LXttlX LXmb.") != 0) { std::cerr << "Problem with ReplaceChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; @@ -568,7 +568,7 @@ static bool CheckStringOperations() } cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb."); - if (strcmp(cres, "Mary Had A Little Lamb.")) { + if (strcmp(cres, "Mary Had A Little Lamb.") != 0) { std::cerr << "Problem with DuplicateString " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; -- cgit v0.12