From cb58cf81635e7ff6935c3ea7c3d1a9d628a38aa8 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 1 Jun 2017 01:42:29 +0300 Subject: [PATCH 1/4] .length() > 0 == !.emepty() --- lib/path.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index ec31cad39..db779b318 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -82,7 +82,7 @@ std::string Path::simplifyPath(std::string originalPath) std::vector pathParts; for (std::size_t i = 0; i < originalPath.size(); ++i) { if (originalPath[i] == '/' || originalPath[i] == '\\') { - if (subPath.length() > 0) { + if (!subPath.empty()) { pathParts.push_back(subPath); subPath = ""; } @@ -92,7 +92,7 @@ std::string Path::simplifyPath(std::string originalPath) subPath.append(1, originalPath[i]); } - if (subPath.length() > 0) + if (!subPath.empty()) pathParts.push_back(subPath); // First filter out all double slashes From 3cd2f2d0927425f076b0b34253711745fa58f467 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 1 Jun 2017 01:49:40 +0300 Subject: [PATCH 2/4] Don't cast bool to bool --- lib/checkautovariables.cpp | 2 +- lib/checkuninitvar.cpp | 2 +- lib/path.cpp | 8 ++++---- lib/symboldatabase.h | 4 ++-- lib/token.h | 2 +- lib/tokenize.cpp | 2 +- test/testclass.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index c98326824..2d9392d11 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -396,7 +396,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) if (!func && tok->type()) return true; - return bool(!retref && retvalue); + return (!retref && retvalue); } //--------------------------------------------------------------------------- diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f55513ec0..8fe6a8207 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -651,7 +651,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var tok = tok->next(); } - return bool(noreturn==nullptr); + return (noreturn == nullptr); } // variable is seen.. diff --git a/lib/path.cpp b/lib/path.cpp index db779b318..57aaf8ba2 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -146,13 +146,13 @@ std::string Path::getPathFromFilename(const std::string &filename) bool Path::sameFileName(const std::string &fname1, const std::string &fname2) { #if defined(__linux__) || defined(__sun) || defined(__hpux) - return bool(fname1 == fname2); + return (fname1 == fname2); #elif defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) - return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0); + return (_stricmp(fname1.c_str(), fname2.c_str()) == 0); #elif defined(__GNUC__) - return bool(strcasecmp(fname1.c_str(), fname2.c_str()) == 0); + return (strcasecmp(fname1.c_str(), fname2.c_str()) == 0); #elif defined(__BORLANDC__) - return bool(stricmp(fname1.c_str(), fname2.c_str()) == 0); + return (stricmp(fname1.c_str(), fname2.c_str()) == 0); #else #error Platform filename compare function needed #endif diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index df4d928fb..37ae27f05 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -185,7 +185,7 @@ class CPPCHECKLIB Variable { * @return true if flag set or false in flag not set */ bool getFlag(unsigned int flag_) const { - return bool((_flags & flag_) != 0); + return ((_flags & flag_) != 0); } /** @@ -656,7 +656,7 @@ class CPPCHECKLIB Function { * @return true if flag set or false in flag not set */ bool getFlag(unsigned int flag) const { - return bool((flags & flag) != 0); + return ((flags & flag) != 0); } /** diff --git a/lib/token.h b/lib/token.h index a3491fe40..66c9161ca 100644 --- a/lib/token.h +++ b/lib/token.h @@ -893,7 +893,7 @@ private: * @return true if flag set or false in flag not set */ bool getFlag(unsigned int flag_) const { - return bool((_flags & flag_) != 0); + return ((_flags & flag_) != 0); } /** diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 14b48f2e9..953eaaa0e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2369,7 +2369,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%")); + return (typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%")); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 9a6a2647f..8af201a47 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -4436,7 +4436,7 @@ private: " x = 0;\n" " }\n" " bool isValid() {\n" - " return bool(x == 0x11224488);\n" + " return (x == 0x11224488);\n" " }\n" "};"); ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const.\n", errout.str()); From 132c0af22af0977a0b5e3fc260b27a4173a2667d Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 1 Jun 2017 02:02:12 +0300 Subject: [PATCH 3/4] Simplify some statements --- cli/filelister.cpp | 10 ++-------- gui/test/data/benchmark/simple.cpp | 2 +- lib/path.cpp | 9 +++------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/cli/filelister.cpp b/cli/filelister.cpp index ad958ab87..c68645950 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -231,19 +231,13 @@ void FileLister::addFiles(std::map &files, const std:: bool FileLister::isDirectory(const std::string &path) { struct stat file_stat; - if (stat(path.c_str(), &file_stat) != -1) - return ((file_stat.st_mode & S_IFMT) == S_IFDIR); - - return false; + return (stat(path.c_str(), &file_stat) != -1 && (file_stat.st_mode & S_IFMT) == S_IFDIR); } bool FileLister::fileExists(const std::string &path) { struct stat file_stat; - if (stat(path.c_str(), &file_stat) != -1) - return ((file_stat.st_mode & S_IFMT) == S_IFREG); - - return false; + return (stat(path.c_str(), &file_stat) != -1 && (file_stat.st_mode & S_IFMT) == S_IFREG); } #endif diff --git a/gui/test/data/benchmark/simple.cpp b/gui/test/data/benchmark/simple.cpp index b0370de7f..80bbb346a 100644 --- a/gui/test/data/benchmark/simple.cpp +++ b/gui/test/data/benchmark/simple.cpp @@ -1064,7 +1064,7 @@ public: /** is variable unused? */ bool unused() const { - return (_read == false && _write == false); + return (!_read && !_write); } const Token *_name; diff --git a/lib/path.cpp b/lib/path.cpp index 57aaf8ba2..f498cd467 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -251,7 +251,7 @@ bool Path::isC(const std::string &path) bool Path::isCPP(const std::string &path) { const std::string extension = getFilenameExtensionInLowerCase(path); - if (extension == ".cpp" || + return extension == ".cpp" || extension == ".cxx" || extension == ".cc" || extension == ".c++" || @@ -259,12 +259,9 @@ bool Path::isCPP(const std::string &path) extension == ".hxx" || extension == ".hh" || extension == ".tpp" || - extension == ".txx") { - return true; - } - + extension == ".txx" || + getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file - return (getFilenameExtension(path) == ".C"); } bool Path::acceptFile(const std::string &path, const std::set &extra) From f5646183cd044e3f44d8cbdf6cc1178727adfb49 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 2 Jun 2017 17:14:56 +0300 Subject: [PATCH 4/4] Move comment to the right place --- lib/path.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/path.cpp b/lib/path.cpp index f498cd467..89584d32f 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -260,8 +260,7 @@ bool Path::isCPP(const std::string &path) extension == ".hh" || extension == ".tpp" || extension == ".txx" || - getFilenameExtension(path) == ".C"; - // In unix, ".C" is considered C++ file + getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file } bool Path::acceptFile(const std::string &path, const std::set &extra)