Merge pull request #910 from mathbunnyru/asalikhov/improve_readability

improve readability
This commit is contained in:
Daniel Marjamäki 2017-06-03 14:33:21 +02:00 committed by GitHub
commit bbde3cc23a
9 changed files with 19 additions and 29 deletions

View File

@ -231,19 +231,13 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &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

View File

@ -1064,7 +1064,7 @@ public:
/** is variable unused? */
bool unused() const {
return (_read == false && _write == false);
return (!_read && !_write);
}
const Token *_name;

View File

@ -396,7 +396,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok)
if (!func && tok->type())
return true;
return bool(!retref && retvalue);
return (!retref && retvalue);
}
//---------------------------------------------------------------------------

View File

@ -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..

View File

@ -82,7 +82,7 @@ std::string Path::simplifyPath(std::string originalPath)
std::vector<std::string> 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.clear();
}
@ -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
@ -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
@ -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,8 @@ bool Path::isCPP(const std::string &path)
extension == ".hxx" ||
extension == ".hh" ||
extension == ".tpp" ||
extension == ".txx") {
return true;
}
// In unix, ".C" is considered C++ file
return (getFilenameExtension(path) == ".C");
extension == ".txx" ||
getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file
}
bool Path::acceptFile(const std::string &path, const std::set<std::string> &extra)

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -2369,7 +2369,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
return false;
}
return bool(typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%"));
return (typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%"));
}

View File

@ -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());