From b41a548d86f8989e790f0150abd3eb337e8c03d0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 Sep 2009 08:18:15 -0400 Subject: [PATCH] Add parentheses around '&&' between '||' for gcc The GNU compiler warns about possible operator precedence mistakes and asks for explicit parentheses (-Wparentheses). We add the parentheses to silence the warning. This also fixes one real logic error in the find_package() implementation by correcting expression evaluation order. --- Source/CPack/cpack.cxx | 9 +++++---- Source/CTest/cmCTestBuildHandler.cxx | 8 ++++---- Source/CursesDialog/cmCursesMainForm.cxx | 20 ++++++++++++-------- Source/cmCMakeMinimumRequired.cxx | 14 +++++++------- Source/cmExecuteProcessCommand.cxx | 4 ++-- Source/cmFileCommand.cxx | 4 ++-- Source/cmFindPackageCommand.cxx | 8 ++++---- Source/cmPolicies.cxx | 2 +- Source/cmSetCommand.cxx | 6 +++--- Source/cmSystemTools.cxx | 12 ++++++------ Source/cmUtilitySourceCommand.cxx | 2 +- 11 files changed, 47 insertions(+), 42 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 51001aa00..2782dca27 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -359,10 +359,11 @@ int main (int argc, char *argv[]) "CPack project name not specified" << std::endl); parsed = 0; } - if ( parsed && !(mf->GetDefinition("CPACK_PACKAGE_VERSION") - || mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") && - mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") - && mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")) ) + if (parsed && + !(mf->GetDefinition("CPACK_PACKAGE_VERSION") || + (mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") && + mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") && + mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")))) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack project version not specified" << std::endl diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index d85df8616..f9982355b 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -611,8 +611,8 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os) it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ ) { cmCTestBuildErrorWarning *cm = &(*it); - if (cm->Error && numErrorsAllowed || - !cm->Error && numWarningsAllowed) + if ((cm->Error && numErrorsAllowed) || + (!cm->Error && numWarningsAllowed)) { if (cm->Error) { @@ -681,8 +681,8 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os) << "\n" << "\t\t" << cmXMLSafe(cm->PostContext).Quotes(false); // is this the last warning or error, if so notify - if (cm->Error && !numErrorsAllowed || - !cm->Error && !numWarningsAllowed) + if ((cm->Error && !numErrorsAllowed) || + (!cm->Error && !numWarningsAllowed)) { os << "\nThe maximum number of reported warnings or errors has been " "reached!!!\n"; diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 4d588a99b..c0c409ea0 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -231,7 +231,8 @@ void cmCursesMainForm::RePost() { cmCacheManager::CacheIterator mit = this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); - if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")) + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -259,7 +260,8 @@ void cmCursesMainForm::RePost() { cmCacheManager::CacheIterator mit = this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); - if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")) + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -327,7 +329,8 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) { cmCacheManager::CacheIterator mit = this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); - if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")) + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -344,7 +347,8 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) { cmCacheManager::CacheIterator mit = this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue()); - if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")) + if (mit.IsAtEnd() || + (!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))) { continue; } @@ -914,10 +918,10 @@ void cmCursesMainForm::HandleInput() this->SearchMode = false; } */ - else if ( key >= 'a' && key <= 'z' || - key >= 'A' && key <= 'Z' || - key >= '0' && key <= '9' || - key == '_' ) + else if ((key >= 'a' && key <= 'z') || + (key >= 'A' && key <= 'Z') || + (key >= '0' && key <= '9') || + (key == '_' )) { if ( this->SearchString.size() < static_cast(x-10) ) { diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx index 49860c597..f3fad8515 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -87,12 +87,12 @@ bool cmCMakeMinimumRequired } // Compare the version numbers. - if(current_major < required_major || - current_major == required_major && - current_minor < required_minor || - current_major == required_major && - current_minor == required_minor && - current_patch < required_patch) + if((current_major < required_major) || + (current_major == required_major && + current_minor < required_minor) || + (current_major == required_major && + current_minor == required_minor && + current_patch < required_patch)) { // The current version is too low. cmOStringStream e; @@ -110,7 +110,7 @@ bool cmCMakeMinimumRequired return false; } - if (required_major < 2 || required_major == 2 && required_minor < 4) + if (required_major < 2 || (required_major == 2 && required_minor < 4)) { this->Makefile->SetPolicyVersion("2.4"); } diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 3b09e484c..28ad80d28 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -298,8 +298,8 @@ bool cmExecuteProcessCommand while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p)) { // Put the output in the right place. - if(p == cmsysProcess_Pipe_STDOUT && !output_quiet || - p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output) + if((p == cmsysProcess_Pipe_STDOUT && !output_quiet) || + (p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output)) { if(output_variable.empty()) { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index f9a7dfc89..47e098f46 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -590,7 +590,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) { // Ignore CR character to make output always have UNIX newlines. } - else if(c >= 0x20 && c < 0x7F || c == '\t' || c == '\f' || + else if((c >= 0x20 && c < 0x7F) || c == '\t' || c == '\f' || (c == '\n' && newline_consume)) { // This is an ASCII character that may be part of a string. @@ -1973,7 +1973,7 @@ bool cmFileInstaller::HandleInstallDestination() if ( ch1 != '/' ) { int relative = 0; - if ( ( ch1 >= 'a' && ch1 <= 'z' || ch1 >= 'A' && ch1 <= 'Z' ) && + if (((ch1 >= 'a' && ch1 <= 'z') || (ch1 >= 'A' && ch1 <= 'Z')) && ch2 == ':' ) { // Assume windows diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 9ac73f885..ff1d94c84 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -900,13 +900,13 @@ void cmFindPackageCommand::FindConfig() bool found = false; // Search for frameworks. - if(!found && this->SearchFrameworkFirst || this->SearchFrameworkOnly) + if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) { found = this->FindFrameworkConfig(); } // Search for apps. - if(!found && this->SearchAppBundleFirst || this->SearchAppBundleOnly) + if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly)) { found = this->FindAppBundleConfig(); } @@ -1136,8 +1136,8 @@ void cmFindPackageCommand::AddPrefixesSystemEnvironment() std::string const& d = *i; // If the path is a PREFIX/bin case then add its parent instead. - if(d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0 || - d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0) + if((d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0) || + (d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0)) { this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath); } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 95bf972b3..ea8726e76 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -497,7 +497,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, } // it is an error if the policy version is less than 2.4 - if (majorVer < 2 || majorVer == 2 && minorVer < 4) + if (majorVer < 2 || (majorVer == 2 && minorVer < 4)) { mf->IssueMessage(cmake::FATAL_ERROR, "An attempt was made to set the policy version of CMake to something " diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index e2714b63d..4b361b016 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -134,9 +134,9 @@ bool cmSetCommand // we should be nice and try to catch some simple screwups if the last or // next to last args are CACHE then they screwed up. If they used FORCE // without CACHE they screwed up - if (args[args.size() - 1] == "CACHE" || - args.size() > 1 && args[args.size() - 2] == "CACHE" || - force && !cache) + if ((args[args.size() - 1] == "CACHE") || + (args.size() > 1 && args[args.size() - 2] == "CACHE") || + (force && !cache)) { this->SetError("given invalid arguments for CACHE mode."); return false; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index d0ed2d634..8a9c06e54 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -510,12 +510,12 @@ std::vector cmSystemTools::ParseArguments(const char* command) bool win_path = false; - if ( command[0] != '/' && command[1] == ':' && command[2] == '\\' || - command[0] == '\"' && command[1] != '/' && command[2] == ':' - && command[3] == '\\' || - command[0] == '\'' && command[1] != '/' && command[2] == ':' - && command[3] == '\\' || - command[0] == '\\' && command[1] == '\\') + if ((command[0] != '/' && command[1] == ':' && command[2] == '\\') || + (command[0] == '\"' && command[1] != '/' && command[2] == ':' + && command[3] == '\\') || + (command[0] == '\'' && command[1] != '/' && command[2] == ':' + && command[3] == '\\') || + (command[0] == '\\' && command[1] == '\\')) { win_path = true; } diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index f8683cee3..929696f17 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -56,7 +56,7 @@ bool cmUtilitySourceCommand { haveCacheValue = (cacheValue && (strstr(cacheValue, "(IntDir)") == 0 || - intDir && strcmp(intDir, "$(IntDir)") == 0) && + (intDir && strcmp(intDir, "$(IntDir)") == 0)) && (this->Makefile->GetCacheMajorVersion() != 0 && this->Makefile->GetCacheMinorVersion() != 0 )); }