diff options
Diffstat (limited to 'Source')
37 files changed, 269 insertions, 242 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index b192df2..3fd8485 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 17) -set(CMake_VERSION_PATCH 20200409) +set(CMake_VERSION_PATCH 20200414) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx index a696549..f5e8744 100644 --- a/Source/CPack/IFW/cmCPackIFWRepository.cxx +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -21,11 +21,7 @@ bool cmCPackIFWRepository::IsValid() const switch (this->Update) { case cmCPackIFWRepository::None: - valid = !this->Url.empty(); - break; case cmCPackIFWRepository::Add: - valid = !this->Url.empty(); - break; case cmCPackIFWRepository::Remove: valid = !this->Url.empty(); break; diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 90c5b2a..35c2b11 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -541,11 +541,11 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) const char* fname = launchDir.GetFile(i); if (this->IsLaunchedErrorFile(fname) && numErrorsAllowed) { numErrorsAllowed--; - fragments.insert(this->CTestLaunchDir + "/" + fname); + fragments.insert(this->CTestLaunchDir + '/' + fname); ++this->TotalErrors; } else if (this->IsLaunchedWarningFile(fname) && numWarningsAllowed) { numWarningsAllowed--; - fragments.insert(this->CTestLaunchDir + "/" + fname); + fragments.insert(this->CTestLaunchDir + '/' + fname); ++this->TotalWarnings; } } diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 45ec390..1209e06 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -152,10 +152,12 @@ private: this->FinishRevision(); } } else if (this->Section == SectionRevisions) { + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if (!this->Rev.Log.empty()) { // Continue the existing log. this->Rev.Log += this->Line; - this->Rev.Log += "\n"; + this->Rev.Log += '\n'; } else if (this->Rev.Rev.empty() && this->RegexRevision.find(this->Line)) { this->Rev.Rev = this->RegexRevision.match(1); @@ -166,7 +168,7 @@ private: } else if (!this->RegexBranches.find(this->Line)) { // Start the log. this->Rev.Log += this->Line; - this->Rev.Log += "\n"; + this->Rev.Log += '\n'; } } return this->Section != SectionEnd; diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index c1ecaf1..7ad87f5 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -957,35 +957,25 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( "valgrind line " << lines[cc] << std::endl, this->Quiet); int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT; - if (vgFIM.find(lines[cc])) { + auto& line = lines[cc]; + if (vgFIM.find(line)) { failure = cmCTestMemCheckHandler::FIM; - } else if (vgFMM.find(lines[cc])) { + } else if (vgFMM.find(line)) { failure = cmCTestMemCheckHandler::FMM; - } else if (vgMLK1.find(lines[cc])) { + } else if (vgMLK1.find(line) || vgMLK2.find(line)) { failure = cmCTestMemCheckHandler::MLK; - } else if (vgMLK2.find(lines[cc])) { - failure = cmCTestMemCheckHandler::MLK; - } else if (vgPAR.find(lines[cc])) { + } else if (vgPAR.find(line)) { failure = cmCTestMemCheckHandler::PAR; - } else if (vgMPK1.find(lines[cc])) { - failure = cmCTestMemCheckHandler::MPK; - } else if (vgMPK2.find(lines[cc])) { + } else if (vgMPK1.find(line) || vgMPK2.find(line)) { failure = cmCTestMemCheckHandler::MPK; - } else if (vgUMC.find(lines[cc])) { + } else if (vgUMC.find(line)) { failure = cmCTestMemCheckHandler::UMC; - } else if (vgUMR1.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR2.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR3.find(lines[cc])) { + } else if (vgUMR1.find(line) || vgUMR2.find(line) || vgUMR3.find(line) || + vgUMR4.find(line) || vgUMR5.find(line)) { failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR4.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR5.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgIPW.find(lines[cc])) { + } else if (vgIPW.find(line)) { failure = cmCTestMemCheckHandler::IPW; - } else if (vgABR.find(lines[cc])) { + } else if (vgABR.find(line)) { failure = cmCTestMemCheckHandler::ABR; } @@ -1049,13 +1039,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckDrMemoryOutput( ostr << l << std::endl; if (drMemoryError.find(l)) { defects++; - if (unaddressableAccess.find(l)) { + if (unaddressableAccess.find(l) || uninitializedRead.find(l)) { results[cmCTestMemCheckHandler::UMR]++; - } else if (uninitializedRead.find(l)) { - results[cmCTestMemCheckHandler::UMR]++; - } else if (leak.find(l)) { - results[cmCTestMemCheckHandler::MLK]++; - } else if (handleLeak.find(l)) { + } else if (leak.find(l) || handleLeak.find(l)) { results[cmCTestMemCheckHandler::MLK]++; } else if (invalidHeapArgument.find(l)) { results[cmCTestMemCheckHandler::FMM]++; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f9850ef..ca65946 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2402,10 +2402,9 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args) test.SkipReturnCode = -1; test.PreviousRuns = 0; if (this->UseIncludeRegExpFlag && - !this->IncludeTestsRegularExpression.find(testname)) { - test.IsInBasedOnREOptions = false; - } else if (this->UseExcludeRegExpFlag && !this->UseExcludeRegExpFirst && - this->ExcludeTestsRegularExpression.find(testname)) { + (!this->IncludeTestsRegularExpression.find(testname) || + (!this->UseExcludeRegExpFirst && + this->ExcludeTestsRegularExpression.find(testname)))) { test.IsInBasedOnREOptions = false; } this->TestList.push_back(test); diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx index 1a5e7c5..84d7de0 100644 --- a/Source/CTest/cmParseCacheCoverage.cxx +++ b/Source/CTest/cmParseCacheCoverage.cxx @@ -4,6 +4,7 @@ #include <cstdlib> #include <map> #include <utility> +#include <vector> #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" @@ -69,26 +70,6 @@ void cmParseCacheCoverage::RemoveUnCoveredFiles() } } -bool cmParseCacheCoverage::SplitString(std::vector<std::string>& args, - std::string const& line) -{ - std::string::size_type pos1 = 0; - std::string::size_type pos2 = line.find(',', 0); - if (pos2 == std::string::npos) { - return false; - } - std::string arg; - while (pos2 != std::string::npos) { - arg = line.substr(pos1, pos2 - pos1); - args.push_back(arg); - pos1 = pos2 + 1; - pos2 = line.find(',', pos1); - } - arg = line.substr(pos1); - args.push_back(arg); - return true; -} - bool cmParseCacheCoverage::ReadCMCovFile(const char* file) { cmsys::ifstream in(file); @@ -97,7 +78,6 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) return false; } std::string line; - std::vector<std::string> separateLine; if (!cmSystemTools::GetLineFromStream(in, line)) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Empty file : " << file @@ -106,8 +86,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) << line << "]\n"); return false; } - separateLine.clear(); - this->SplitString(separateLine, line); + std::vector<std::string> separateLine = + cmSystemTools::SplitString(line, ','); if (separateLine.size() != 4 || separateLine[0] != "Routine" || separateLine[1] != "Line" || separateLine[2] != "RtnLine" || separateLine[3] != "Code") { @@ -120,10 +100,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) std::string routine; std::string filepath; while (cmSystemTools::GetLineFromStream(in, line)) { - // clear out line argument vector - separateLine.clear(); // parse the comma separated line - this->SplitString(separateLine, line); + separateLine = cmSystemTools::SplitString(line, ','); // might have more because code could have a quoted , in it // but we only care about the first 3 args anyway if (separateLine.size() < 4) { diff --git a/Source/CTest/cmParseCacheCoverage.h b/Source/CTest/cmParseCacheCoverage.h index 3b554f3..a8200b7 100644 --- a/Source/CTest/cmParseCacheCoverage.h +++ b/Source/CTest/cmParseCacheCoverage.h @@ -6,7 +6,6 @@ #include "cmConfigure.h" // IWYU pragma: keep #include <string> -#include <vector> #include "cmParseMumpsCoverage.h" @@ -31,8 +30,6 @@ protected: void RemoveUnCoveredFiles(); // Read a single mcov file bool ReadCMCovFile(const char* f); - // split a string based on , - bool SplitString(std::vector<std::string>& args, std::string const& line); }; #endif diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx index afd2b6b..664ba2f 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -41,7 +41,8 @@ void cmCursesLongMessageForm::UpdateContent(std::string const& output, this->Title = title; if (!output.empty() && this->Messages.size() < MAX_CONTENT_SIZE) { - this->Messages.append("\n" + output); + this->Messages.push_back('\n'); + this->Messages.append(output); form_driver(this->Form, REQ_NEW_LINE); this->DrawMessage(output.c_str()); } diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 276bf64..4daf726 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -804,6 +804,9 @@ bool CMakeSetupDialog::setupFirstConfigure() QString systemVersion = dialog.getSystemVersion(); m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION", tr("CMake System Version"), systemVersion, false); + QString systemProcessor = dialog.getSystemProcessor(); + m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_PROCESSOR", + tr("CMake System Processor"), systemProcessor, false); QString cxxCompiler = dialog.getCXXCompiler(); m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER", tr("CXX compiler."), cxxCompiler, false); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index c5505f9..35a8952 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1941,13 +1941,11 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, else if (this->CheckArgument(arg, "--debug"_s)) { this->Impl->Debug = true; this->Impl->ShowLineNumbers = true; - } else if (this->CheckArgument(arg, "--group"_s) && i < args.size() - 1) { - i++; - this->Impl->SpecificGroup = args[i]; - } - // This is an undocumented / deprecated option. - // "Track" has been renamed to "Group". - else if (this->CheckArgument(arg, "--track"_s) && i < args.size() - 1) { + } else if ((this->CheckArgument(arg, "--group"_s) || + // This is an undocumented / deprecated option. + // "Track" has been renamed to "Group". + this->CheckArgument(arg, "--track"_s)) && + i < args.size() - 1) { i++; this->Impl->SpecificGroup = args[i]; } else if (this->CheckArgument(arg, "--show-line-numbers"_s)) { diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 8d27699..d8a6204 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -998,15 +998,16 @@ std::string cmComputeLinkInformation::CreateExtensionRegex( std::string cmComputeLinkInformation::NoCaseExpression(const char* str) { std::string ret; + ret.reserve(strlen(str) * 4); const char* s = str; while (*s) { if (*s == '.') { ret += *s; } else { - ret += "["; + ret += '['; ret += static_cast<char>(tolower(*s)); ret += static_cast<char>(toupper(*s)); - ret += "]"; + ret += ']'; } s++; } @@ -1440,7 +1441,6 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item, } case cmPolicies::OLD: // OLD behavior does not warn. - break; case cmPolicies::NEW: // NEW behavior will not get here. break; diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index 8767386..bac9337 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -2,6 +2,12 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmConfigureFileCommand.h" +#include <set> + +#include <cm/string_view> + +#include "cm_static_string_view.hxx" + #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -56,6 +62,18 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args, bool copyOnly = false; bool escapeQuotes = false; + static std::set<cm::string_view> noopOptions = { + /* Legacy. */ + "IMMEDIATE"_s, + /* Handled by NewLineStyle member. */ + "NEWLINE_STYLE"_s, + "LF"_s, + "UNIX"_s, + "CRLF"_s, + "WIN32"_s, + "DOS"_s, + }; + std::string unknown_args; bool atOnly = false; for (unsigned int i = 2; i < args.size(); ++i) { @@ -70,12 +88,8 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args, escapeQuotes = true; } else if (args[i] == "@ONLY") { atOnly = true; - } else if (args[i] == "IMMEDIATE") { - /* Ignore legacy option. */ - } else if (args[i] == "NEWLINE_STYLE" || args[i] == "LF" || - args[i] == "UNIX" || args[i] == "CRLF" || args[i] == "WIN32" || - args[i] == "DOS") { - /* Options handled by NewLineStyle member above. */ + } else if (noopOptions.find(args[i]) != noopOptions.end()) { + /* Ignore no-op options. */ } else { unknown_args += " "; unknown_args += args[i]; diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 9c26f61..9175dac 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -40,6 +40,8 @@ static std::string const kCMAKE_CXX_LINK_NO_PIE_SUPPORTED = "CMAKE_CXX_LINK_NO_PIE_SUPPORTED"; static std::string const kCMAKE_CXX_LINK_PIE_SUPPORTED = "CMAKE_CXX_LINK_PIE_SUPPORTED"; +static std::string const kCMAKE_CUDA_COMPILER_TARGET = + "CMAKE_CUDA_COMPILER_TARGET"; static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS"; static std::string const kCMAKE_LINK_SEARCH_END_STATIC = "CMAKE_LINK_SEARCH_END_STATIC"; @@ -711,6 +713,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, vars.insert(kCMAKE_C_COMPILER_TARGET); vars.insert(kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN); vars.insert(kCMAKE_CXX_COMPILER_TARGET); + vars.insert(kCMAKE_CUDA_COMPILER_TARGET); vars.insert(kCMAKE_ENABLE_EXPORTS); vars.insert(kCMAKE_LINK_SEARCH_END_STATIC); vars.insert(kCMAKE_LINK_SEARCH_START_STATIC); diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 666306c..c45cd1c 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -29,12 +29,10 @@ static void cmFortranModuleAppendUpperLower(std::string const& mod, std::string& mod_lower) { std::string::size_type ext_len = 0; - if (cmHasLiteralSuffix(mod, ".mod")) { + if (cmHasLiteralSuffix(mod, ".mod") || cmHasLiteralSuffix(mod, ".sub")) { ext_len = 4; } else if (cmHasLiteralSuffix(mod, ".smod")) { ext_len = 5; - } else if (cmHasLiteralSuffix(mod, ".sub")) { - ext_len = 4; } std::string const& name = mod.substr(0, mod.size() - ext_len); std::string const& ext = mod.substr(mod.size() - ext_len); diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index de40c77..bf7555d 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -204,9 +204,7 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles( case cmStateEnums::STATIC_LIBRARY: { projectType = "Static Library"; } break; - case cmStateEnums::SHARED_LIBRARY: { - projectType = "Dynamic Library"; - } break; + case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: { projectType = "Dynamic Library"; } break; diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 1c5bcaa..b65f097 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -981,7 +981,6 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const } } break; case cmStateEnums::INTERFACE_LIBRARY: - break; default: break; } diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 271bbee..01fac5a 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -129,9 +129,8 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator& lg, if (targetName == "edit_cache") { const char* editCommand = localGen->GetMakefile()->GetDefinition("CMAKE_EDIT_COMMAND"); - if (editCommand == nullptr) { - insertTarget = false; - } else if (strstr(editCommand, "ccmake") != nullptr) { + if (editCommand == nullptr || + strstr(editCommand, "ccmake") != nullptr) { insertTarget = false; } } @@ -274,7 +273,7 @@ std::string cmExtraKateGenerator::GenerateProjectName( const std::string& name, const std::string& type, const std::string& path) const { - return name + (type.empty() ? "" : "-") + type + "@" + path; + return name + (type.empty() ? "" : "-") + type + '@' + path; } std::string cmExtraKateGenerator::GetPathBasename( diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index e996327..d1517fe 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -279,9 +279,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) } else if (args[i] == "MODULE") { moduleArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "CONFIG") { configArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "NO_MODULE") { configArgs.insert(i); doing = DoingNone; @@ -318,6 +322,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) this->NoSystemRegistry = true; configArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "NO_CMAKE_BUILDS_PATH") { // Ignore legacy option. configArgs.insert(i); diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 4b88bea..599b1d2 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -85,7 +85,7 @@ struct cmFindProgramHelper this->TestNameExt = cmStrCat(name, ext); this->TestPath = cmSystemTools::CollapseFullPath(this->TestNameExt, path); - bool exists = cmSystemTools::FileExists(this->TestPath, true); + bool exists = cmSystemTools::FileIsExecutable(this->TestPath); exists ? this->DebugSearches.FoundAt(this->TestPath) : this->DebugSearches.FailedAt(this->TestPath); if (exists) { diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 611f7b0..93eb8fb 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1227,7 +1227,6 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty( return result; case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: // No error. We just skip cyclic references. - return result; case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: // No error. We have already seen this transitive property. return result; @@ -1295,10 +1294,9 @@ std::string AddSwiftInterfaceIncludeDirectories( dag.ReportError(nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",Swift_MODULE_DIRECTORY>"); - return ""; + CM_FALLTHROUGH; case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: // No error. We just skip cyclic references. - return ""; case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: // No error. We have already seen this transitive property. return ""; @@ -1689,10 +1687,14 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, std::string ext = cmSystemTools::LowerCase(sf->GetExtension()); if (sf->GetCustomCommand()) { kind = SourceKindCustomCommand; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (this->Target->GetType() == cmStateEnums::UTILITY) { kind = SourceKindExtra; } else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) { kind = SourceKindUnityBatched; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) { kind = SourceKindHeader; } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ccbbf53..4a6f6fb 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2253,10 +2253,12 @@ std::string cmGlobalGenerator::IndexGeneratorTargetUniquely( // Use a ":" prefix to avoid conflict with project-defined targets. // We must satisfy cmGeneratorExpression::IsValidTargetName so use no // other special characters. - char buf[1 + sizeof(gt) * 2]; + constexpr size_t sizeof_ptr = + sizeof(gt); // NOLINT(bugprone-sizeof-expression) + char buf[1 + sizeof_ptr * 2]; char* b = buf; *b++ = ':'; - for (size_t i = 0; i < sizeof(gt); ++i) { + for (size_t i = 0; i < sizeof_ptr; ++i) { unsigned char const c = reinterpret_cast<unsigned char const*>(>)[i]; *b++ = hexDigits[(c & 0xf0) >> 4]; *b++ = hexDigits[(c & 0x0f)]; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e74d618..bdc03c7 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3550,7 +3550,7 @@ std::string cmGlobalXCodeGenerator::RelativeToBinary(const std::string& p) std::string cmGlobalXCodeGenerator::XCodeEscapePath(const std::string& p) { - if (p.find(' ') != std::string::npos) { + if (p.find_first_of(" []") != std::string::npos) { std::string t = cmStrCat('"', p, '"'); return t; } diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 704db66..c9b22b6 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -661,7 +661,6 @@ bool HandleTargetsMode(std::vector<std::string> const& args, // Nothing to do. An INTERFACE_LIBRARY can be installed, but the // only effect of that is to make it exportable. It installs no // other files itself. - break; default: // This should never happen due to the above type check. // Ignore the case. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f5ca5f4..e6083d3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2070,11 +2070,9 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, case cmStateEnums::OBJECT_LIBRARY: // An object library has no single file on which to depend. // This was listed to get the target-level dependency. - return false; case cmStateEnums::INTERFACE_LIBRARY: // An interface library has no file on which to depend. // This was listed to get the target-level dependency. - return false; case cmStateEnums::UTILITY: case cmStateEnums::GLOBAL_TARGET: // A utility target has no file on which to depend. This was listed @@ -3389,11 +3387,12 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( // Select a nice-looking reference to the source file to construct // the object file name. std::string objectName; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if ((relSource && !relBinary) || (subSource && !subBinary)) { objectName = relFromSource; - } else if ((relBinary && !relSource) || (subBinary && !subSource)) { - objectName = relFromBinary; - } else if (relFromBinary.length() < relFromSource.length()) { + } else if ((relBinary && !relSource) || (subBinary && !subSource) || + relFromBinary.length() < relFromSource.length()) { objectName = relFromBinary; } else { objectName = relFromSource; @@ -3552,7 +3551,6 @@ bool cmLocalGenerator::NeedBackwardsCompatibility_2_4() break; case cmPolicies::NEW: // New behavior is to ignore the variable. - return false; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: // This will never be the case because the only way to require diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 69f316d..15b8b92 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -24,6 +24,7 @@ #include "cm_jsoncpp_value.h" #include "cm_jsoncpp_writer.h" +#include "cm_static_string_view.hxx" #include "cm_sys_stat.h" #include "cmAlgorithms.h" @@ -2513,10 +2514,7 @@ void cmMakefile::ExpandVariablesCMP0019() for (auto l = linkLibs.begin(); l != linkLibs.end(); ++l) { std::string libName = *l; - if (libName == "optimized") { - ++l; - libName = *l; - } else if (libName == "debug") { + if (libName == "optimized"_s || libName == "debug"_s) { ++l; libName = *l; } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 5c8bc98..dea3f8a 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -72,6 +72,7 @@ static const char* idToVersion(cmPolicies::PolicyID id) #define POLICY_CASE(ID, V_MAJOR, V_MINOR, V_PATCH) \ case cmPolicies::ID: \ return #V_MAJOR "." #V_MINOR "." #V_PATCH; + // NOLINTNEXTLINE(bugprone-branch-clone) CM_FOR_EACH_POLICY_ID_VERSION(POLICY_CASE) #undef POLICY_CASE case cmPolicies::CMPCOUNT: @@ -90,6 +91,7 @@ static bool isPolicyNewerThan(cmPolicies::PolicyID id, unsigned int majorV, (majorV == (V_MAJOR) && minorV + 1 < (V_MINOR) + 1) || \ (majorV == (V_MAJOR) && minorV == (V_MINOR) && \ patchV + 1 < (V_PATCH) + 1)); + // NOLINTNEXTLINE(bugprone-branch-clone) CM_FOR_EACH_POLICY_ID_VERSION(POLICY_CASE) #undef POLICY_CASE case cmPolicies::CMPCOUNT: diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index c39d162..26e93bb 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -166,6 +166,8 @@ void cmRST::ProcessLine(std::string const& line) this->Markup = (line.find_first_not_of(" \t", 2) == std::string::npos ? MarkupEmpty : MarkupNormal); + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if (this->CMakeDirective.find(line)) { // Output cmake domain directives and their content normally. this->NormalLine(line); diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index 52bde7c..cfe3087 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -39,6 +39,8 @@ bool cmSeparateArgumentsCommand(std::vector<std::string> const& args, if (doing == DoingVariable) { var = arg; doing = DoingMode; + // This will always clone one of the other blocks. + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (doing == DoingMode && arg == "NATIVE_COMMAND") { #ifdef _WIN32 mode = ModeWindows; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2ec893f..ea1d8ca 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -642,6 +642,8 @@ void cmake::SetArgs(const std::vector<std::string>& args) path = cmSystemTools::CollapseFullPath(path); cmSystemTools::ConvertToUnixSlashes(path); this->SetHomeDirectory(path); + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (cmHasLiteralPrefix(arg, "-O")) { // There is no local generate anymore. Ignore -O option. } else if (cmHasLiteralPrefix(arg, "-B")) { @@ -681,27 +683,16 @@ void cmake::SetArgs(const std::vector<std::string>& args) this->VSSolutionFile = args[++i]; } #endif - else if (cmHasLiteralPrefix(arg, "-D")) { + else if (cmHasLiteralPrefix(arg, "-D") || cmHasLiteralPrefix(arg, "-U") || + cmHasLiteralPrefix(arg, "-C")) { // skip for now - // in case '-D var=val' is given, also skip the next - // in case '-Dvar=val' is given, don't skip the next - if (arg.size() == 2) { - ++i; - } - } else if (cmHasLiteralPrefix(arg, "-U")) { - // skip for now - // in case '-U var' is given, also skip the next - // in case '-Uvar' is given, don't skip the next - if (arg.size() == 2) { - ++i; - } - } else if (cmHasLiteralPrefix(arg, "-C")) { - // skip for now - // in case '-C path' is given, also skip the next - // in case '-Cpath' is given, don't skip the next + // in case '-[DUC] argval' var' is given, also skip the next + // in case '-[DUC]argval' is given, don't skip the next if (arg.size() == 2) { ++i; } + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (cmHasLiteralPrefix(arg, "-P")) { // skip for now i++; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index c3bd160..49d04a6 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1972,9 +1972,8 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg, // Parse the link command to extract information we need. for (; arg != argEnd; ++arg) { - if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0) { - this->Incremental = true; - } else if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) { + if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0 || + cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) { this->Incremental = true; } else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0) { this->LinkGeneratesManifest = false; diff --git a/Source/kwsys/Base64.c b/Source/kwsys/Base64.c index bf876f2..4265018 100644 --- a/Source/kwsys/Base64.c +++ b/Source/kwsys/Base64.c @@ -130,7 +130,10 @@ size_t kwsysBase64_Encode(const unsigned char* input, size_t length, /* Decode 4 bytes into a 3 byte string. */ int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest) { - unsigned char d0, d1, d2, d3; + unsigned char d0; + unsigned char d1; + unsigned char d2; + unsigned char d3; d0 = kwsysBase64DecodeChar(src[0]); d1 = kwsysBase64DecodeChar(src[1]); diff --git a/Source/kwsys/MD5.c b/Source/kwsys/MD5.c index 97cf9ba..7ae2630 100644 --- a/Source/kwsys/MD5.c +++ b/Source/kwsys/MD5.c @@ -171,8 +171,10 @@ typedef struct md5_state_s static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) { - md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], - d = pms->abcd[3]; + md5_word_t a = pms->abcd[0]; + md5_word_t b = pms->abcd[1]; + md5_word_t c = pms->abcd[2]; + md5_word_t d = pms->abcd[3]; md5_word_t t; #if BYTE_ORDER > 0 /* Define storage only for big-endian CPUs. */ @@ -227,9 +229,10 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/) # else # define xbuf X /* (static only) */ # endif - for (i = 0; i < 16; ++i, xp += 4) + for (i = 0; i < 16; ++i, xp += 4) { xbuf[i] = (md5_word_t)(xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24)); + } } #endif } @@ -367,34 +370,39 @@ static void md5_append(md5_state_t* pms, const md5_byte_t* data, size_t nbytes) size_t offset = (pms->count[0] >> 3) & 63; md5_word_t nbits = (md5_word_t)(nbytes << 3); - if (nbytes <= 0) + if (nbytes <= 0) { return; + } /* Update the message length. */ pms->count[1] += (md5_word_t)(nbytes >> 29); pms->count[0] += nbits; - if (pms->count[0] < nbits) + if (pms->count[0] < nbits) { pms->count[1]++; + } /* Process an initial partial block. */ if (offset) { size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes); memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) + if (offset + copy < 64) { return; + } p += copy; left -= copy; md5_process(pms, pms->buf); } /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) + for (; left >= 64; p += 64, left -= 64) { md5_process(pms, p); + } /* Process a final partial block. */ - if (left) + if (left) { memcpy(pms->buf, p, left); + } } /* Finish the message and return the digest. */ diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 5fde0b0..d3a09ed 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -432,8 +432,8 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) char const* const* c = command; kwsysProcess_ptrdiff_t n = 0; kwsysProcess_ptrdiff_t i = 0; - while (*c++) - ; + while (*c++) { + } n = c - command - 1; newCommands[cp->NumberOfCommands] = (char**)malloc((size_t)(n + 1) * sizeof(char*)); @@ -685,7 +685,8 @@ const char* kwsysProcess_GetErrorString(kwsysProcess* cp) { if (!cp) { return "Process management structure could not be allocated"; - } else if (cp->State == kwsysProcess_State_Error) { + } + if (cp->State == kwsysProcess_State_Error) { return cp->ErrorMessage; } return "Success"; @@ -695,7 +696,8 @@ const char* kwsysProcess_GetExceptionString(kwsysProcess* cp) { if (!(cp && cp->ProcessResults && (cp->NumberOfCommands > 0))) { return "GetExceptionString called with NULL process management structure"; - } else if (cp->State == kwsysProcess_State_Exception) { + } + if (cp->State == kwsysProcess_State_Exception) { return cp->ProcessResults[cp->NumberOfCommands - 1].ExitExceptionString; } return "No exception"; @@ -787,8 +789,8 @@ void kwsysProcess_Execute(kwsysProcess* cp) /* Some platforms specify that the chdir call may be interrupted. Repeat the call until it finishes. */ - while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)) - ; + while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)) { + } if (r < 0) { kwsysProcessCleanup(cp, 1); return; @@ -1014,8 +1016,8 @@ void kwsysProcess_Execute(kwsysProcess* cp) if (cp->RealWorkingDirectory) { /* Some platforms specify that the chdir call may be interrupted. Repeat the call until it finishes. */ - while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) - ; + while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) { + } free(cp->RealWorkingDirectory); cp->RealWorkingDirectory = 0; } @@ -1100,22 +1102,22 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length, if (wd.PipeId) { /* Data are ready on a pipe. */ return wd.PipeId; - } else if (wd.Expired) { + } + if (wd.Expired) { /* A timeout has expired. */ if (wd.User) { /* The user timeout has expired. It has no time left. */ return kwsysProcess_Pipe_Timeout; - } else { - /* The process timeout has expired. Kill the children now. */ - kwsysProcess_Kill(cp); - cp->Killed = 0; - cp->TimeoutExpired = 1; - return kwsysProcess_Pipe_None; } - } else { - /* No pipes are left open. */ + + /* The process timeout has expired. Kill the children now. */ + kwsysProcess_Kill(cp); + cp->Killed = 0; + cp->TimeoutExpired = 1; return kwsysProcess_Pipe_None; } + /* No pipes are left open. */ + return kwsysProcess_Pipe_None; } static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, @@ -1184,7 +1186,7 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, /* Make sure the set is empty (it should always be empty here anyway). */ - FD_ZERO(&cp->PipeSet); + FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration) /* Setup a timeout if required. */ if (wd->TimeoutTime.tv_sec < 0) { @@ -1227,7 +1229,8 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, /* Select's timeout expired. */ wd->Expired = 1; return 1; - } else if (numReady < 0) { + } + if (numReady < 0) { /* Select returned an error. Leave the error description in the pipe buffer. */ strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE); @@ -1367,11 +1370,13 @@ int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout) cp->ProcessResults[prPipe].State = kwsysProcess_StateByIndex_Exited; cp->ProcessResults[prPipe].ExitException = kwsysProcess_Exception_None; cp->ProcessResults[prPipe].ExitValue = + // NOLINTNEXTLINE(google-readability-casting) (int)WEXITSTATUS(cp->ProcessResults[prPipe].ExitCode); } else if (WIFSIGNALED(cp->ProcessResults[prPipe].ExitCode)) { /* The child received an unhandled signal. */ cp->ProcessResults[prPipe].State = kwsysProcess_State_Exception; kwsysProcessSetExitExceptionByIndex( + // NOLINTNEXTLINE(google-readability-casting) cp, (int)WTERMSIG(cp->ProcessResults[prPipe].ExitCode), prPipe); } else { /* Error getting the child return code. */ @@ -1450,8 +1455,8 @@ void kwsysProcess_Kill(kwsysProcess* cp) /* Reap the child. Keep trying until the call is not interrupted. */ - while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) - ; + while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) { + } } } @@ -1502,7 +1507,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp) cp->PipesLeft = 0; cp->CommandsLeft = 0; #if KWSYSPE_USE_SELECT - FD_ZERO(&cp->PipeSet); + FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration) #endif cp->State = kwsysProcess_State_Starting; cp->Killed = 0; @@ -1591,16 +1596,16 @@ static void kwsysProcessCleanup(kwsysProcess* cp, int error) /* Reap the child. Keep trying until the call is not interrupted. */ while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } } } /* Restore the working directory. */ if (cp->RealWorkingDirectory) { - while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) - ; + while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) { + } } } @@ -1636,8 +1641,8 @@ static void kwsysProcessCleanupDescriptor(int* pfd) if (pfd && *pfd > 2) { /* Keep trying to close until it is not interrupted by a * signal. */ - while ((close(*pfd) < 0) && (errno == EINTR)) - ; + while ((close(*pfd) < 0) && (errno == EINTR)) { + } *pfd = -1; } } @@ -1662,8 +1667,8 @@ static void kwsysProcessClosePipes(kwsysProcess* cp) read until the operation is not interrupted. */ while ((read(cp->PipeReadEnds[i], cp->PipeBuffer, KWSYSPE_PIPE_BUFFER_SIZE) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } #endif @@ -1690,7 +1695,8 @@ int decc$set_child_standard_streams(int fd1, int fd2, int fd3); static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, kwsysProcessCreateInformation* si) { - sigset_t mask, old_mask; + sigset_t mask; + sigset_t old_mask; int pgidPipe[2]; char tmp; ssize_t readRes; @@ -1818,8 +1824,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, /* Make sure the child is in the process group before we proceed. This avoids race conditions with calls to the kill function that we make for signalling process groups. */ - while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0) - ; + while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0) { + } if (readRes < 0) { sigprocmask(SIG_SETMASK, &old_mask, 0); kwsysProcessCleanupDescriptor(&si->ErrorPipe[0]); @@ -1847,8 +1853,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex, /* Keep trying to read until the operation is not interrupted. */ while (((n = read(si->ErrorPipe[0], cp->ErrorMessage + total, (size_t)(KWSYSPE_PIPE_BUFFER_SIZE - total))) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } if (n > 0) { total += n; } @@ -2000,28 +2006,26 @@ static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime, if (timeoutTime->tv_sec < 0) { /* No timeout time has been requested. */ return 0; - } else { - /* Calculate the remaining time. */ - kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent(); - kwsysProcessTime timeLeft = - kwsysProcessTimeSubtract(*timeoutTime, currentTime); - if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) { - /* Caller has explicitly requested a zero timeout. */ - timeLeft.tv_sec = 0; - timeLeft.tv_usec = 0; - } + } + /* Calculate the remaining time. */ + kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent(); + kwsysProcessTime timeLeft = + kwsysProcessTimeSubtract(*timeoutTime, currentTime); + if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) { + /* Caller has explicitly requested a zero timeout. */ + timeLeft.tv_sec = 0; + timeLeft.tv_usec = 0; + } - if (timeLeft.tv_sec < 0 || - (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) { - /* Timeout has already expired. */ - return 1; - } else { - /* There is some time left. */ - timeoutLength->tv_sec = timeLeft.tv_sec; - timeoutLength->tv_usec = timeLeft.tv_usec; - return 0; - } + if (timeLeft.tv_sec < 0 || + (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) { + /* Timeout has already expired. */ + return 1; } + /* There is some time left. */ + timeoutLength->tv_sec = timeLeft.tv_sec; + timeoutLength->tv_usec = timeLeft.tv_usec; + return 0; } static kwsysProcessTime kwsysProcessTimeGetCurrent(void) @@ -2426,41 +2430,39 @@ static pid_t kwsysProcessFork(kwsysProcess* cp, if (middle_pid < 0) { /* Fork failed. Return as if we were not detaching. */ return middle_pid; - } else if (middle_pid == 0) { + } + if (middle_pid == 0) { /* This is the intermediate process. Create the real child. */ pid_t child_pid = fork(); if (child_pid == 0) { /* This is the real child process. There is nothing to do here. */ return 0; - } else { - /* Use the error pipe to report the pid to the real parent. */ - while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) && - (errno == EINTR)) - ; - - /* Exit without cleanup. The parent holds all resources. */ - kwsysProcessExit(); - return 0; /* Never reached, but avoids SunCC warning. */ } - } else { - /* This is the original parent process. The intermediate - process will use the error pipe to report the pid of the - detached child. */ - pid_t child_pid; - int status; - while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) && - (errno == EINTR)) - ; + /* Use the error pipe to report the pid to the real parent. */ + while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) && + (errno == EINTR)) { + } - /* Wait for the intermediate process to exit and clean it up. */ - while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) - ; - return child_pid; + /* Exit without cleanup. The parent holds all resources. */ + kwsysProcessExit(); + return 0; /* Never reached, but avoids SunCC warning. */ } - } else { - /* Not creating a detached process. Use normal fork. */ - return fork(); + /* This is the original parent process. The intermediate + process will use the error pipe to report the pid of the + detached child. */ + pid_t child_pid; + int status; + while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) && + (errno == EINTR)) { + } + + /* Wait for the intermediate process to exit and clean it up. */ + while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) { + } + return child_pid; } + /* Not creating a detached process. Use normal fork. */ + return fork(); } #endif @@ -2727,8 +2729,8 @@ static int kwsysProcessesAdd(kwsysProcess* cp) sigemptyset(&newSigAction.sa_mask); while ((sigaction(SIGCHLD, &newSigAction, &kwsysProcessesOldSigChldAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } /* Install our handler for SIGINT / SIGTERM. Repeat call until it is not interrupted. */ @@ -2736,15 +2738,15 @@ static int kwsysProcessesAdd(kwsysProcess* cp) sigaddset(&newSigAction.sa_mask, SIGTERM); while ((sigaction(SIGINT, &newSigAction, &kwsysProcessesOldSigIntAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } sigemptyset(&newSigAction.sa_mask); sigaddset(&newSigAction.sa_mask, SIGINT); while ((sigaction(SIGTERM, &newSigAction, &kwsysProcessesOldSigIntAction) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } } } @@ -2775,14 +2777,14 @@ static void kwsysProcessesRemove(kwsysProcess* cp) /* Restore the signal handlers. Repeat call until it is not interrupted. */ while ((sigaction(SIGCHLD, &kwsysProcessesOldSigChldAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } while ((sigaction(SIGINT, &kwsysProcessesOldSigIntAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } while ((sigaction(SIGTERM, &kwsysProcessesOldSigTermAction, 0) < 0) && - (errno == EINTR)) - ; + (errno == EINTR)) { + } /* Free the table of process pointers since it is now empty. This is safe because the signal handler has been removed. */ @@ -2808,7 +2810,10 @@ static void kwsysProcessesSignalHandler(int signum #endif ) { - int i, j, procStatus, old_errno = errno; + int i; + int j; + int procStatus; + int old_errno = errno; #if KWSYSPE_USE_SIGINFO (void)info; (void)ucontext; @@ -2865,8 +2870,8 @@ static void kwsysProcessesSignalHandler(int signum memset(&defSigAction, 0, sizeof(defSigAction)); defSigAction.sa_handler = SIG_DFL; sigemptyset(&defSigAction.sa_mask); - while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR)) - ; + while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR)) { + } /* Unmask the signal. */ sigemptyset(&unblockSet); sigaddset(&unblockSet, signum); diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 8ec3058..3a6ceec 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -1904,7 +1904,7 @@ std::vector<std::string> SystemTools::SplitString(const std::string& p, paths.emplace_back("/"); } std::string::size_type pos1 = 0; - std::string::size_type pos2 = path.find(sep, pos1 + 1); + std::string::size_type pos2 = path.find(sep, pos1); while (pos2 != std::string::npos) { paths.push_back(path.substr(pos1, pos2 - pos1)); pos1 = pos2 + 1; diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c index 39aaa23..cde466a 100644 --- a/Source/kwsys/testProcess.c +++ b/Source/kwsys/testProcess.c @@ -631,7 +631,8 @@ int main(int argc, const char* argv[]) } fprintf(stderr, "Invalid test number %d.\n", n); return 1; - } else if (n >= 1 && n <= 10) { + } + if (n >= 1 && n <= 10) { /* This is the parent process for a requested test number. */ int states[10] = { kwsysProcess_State_Exited, kwsysProcess_State_Exited, diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index aa38aec..8909b49 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -1120,6 +1120,42 @@ static bool CheckURLParsing() return ret; } +static bool CheckSplitString() +{ + bool ret = true; + + auto check_split = [](std::string const& input, + std::initializer_list<const char*> expected) -> bool { + auto const components = kwsys::SystemTools::SplitString(input, '/'); + if (components.size() != expected.size()) { + std::cerr << "Incorrect split count for " << input << ": " + << components.size() << std::endl; + return false; + } + size_t i = 0; + for (auto& part : expected) { + if (components[i] != part) { + std::cerr << "Incorrect split component " << i << " for " << input + << ": " << components[i] << std::endl; + return false; + } + ++i; + } + return true; + }; + + // No separators + ret &= check_split("nosep", { "nosep" }); + // Simple + ret &= check_split("first/second", { "first", "second" }); + // Separator at beginning + ret &= check_split("/starts/sep", { "", "starts", "sep" }); + // Separator at end + ret &= check_split("ends/sep/", { "ends", "sep", "" }); + + return ret; +} + int testSystemTools(int, char* []) { bool res = true; @@ -1169,5 +1205,7 @@ int testSystemTools(int, char* []) res &= CheckURLParsing(); + res &= CheckSplitString(); + return res ? 0 : 1; } |