diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index 022efa0ef..38414fdf6 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -198,6 +198,7 @@ bool ApplicationList::checkAndAddApplication(const QString& appPath, const QStri return false; } +#ifdef _WIN32 bool ApplicationList::findDefaultWindowsEditor() { bool foundOne = false; @@ -264,3 +265,4 @@ bool ApplicationList::findDefaultWindowsEditor() return foundOne; } +#endif diff --git a/gui/applicationlist.h b/gui/applicationlist.h index d2249e2ab..189ea62aa 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -108,11 +108,13 @@ protected: */ void clear(); +#ifdef _WIN32 /** * @brief Find editor used by default in Windows. * Check if Notepad++ is installed and use it. If not, use Notepad. */ bool findDefaultWindowsEditor(); +#endif private: diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 4710de816..d10836c0d 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -268,7 +268,7 @@ private: void setLanguage(const QString &code); /** @brief Event coming when application is about to close. */ - virtual void closeEvent(QCloseEvent *event); + void closeEvent(QCloseEvent *event) override; /** * @brief Helper function to toggle all show error menu items diff --git a/gui/resultstree.h b/gui/resultstree.h index 0e32f4944..12114485d 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -177,7 +177,7 @@ public: */ ShowTypes mShowSeverities; - virtual void keyPressEvent(QKeyEvent *event); + void keyPressEvent(QKeyEvent *event) override; signals: /** @@ -294,7 +294,7 @@ protected slots: * @param current Model index to specify new selected item. * @param previous Model index to specify previous selected item. */ - virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); + void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; protected: @@ -365,7 +365,7 @@ protected: * * @param e Event */ - void contextMenuEvent(QContextMenuEvent * e); + void contextMenuEvent(QContextMenuEvent * e) override; /** * @brief Add a new error item beneath a file or a backtrace item beneath an error diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c87932321..b5da9227a 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3306,14 +3306,6 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const return (result.type == FwdAnalysis::Result::Type::NONE || result.type == FwdAnalysis::Result::Type::RETURN) && !possiblyAliased(expr, startToken); } -std::vector FwdAnalysis::valueFlow(const Token *expr, const Token *startToken, const Token *endToken) -{ - mWhat = What::ValueFlow; - mValueFlowKnown = true; - check(expr, startToken, endToken); - return mValueFlow; -} - bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) const { if (expr->isUnaryOp("*")) diff --git a/lib/astutils.h b/lib/astutils.h index 284eed928..2a13a7386 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -363,8 +363,6 @@ public: const Token *token; }; - std::vector valueFlow(const Token *expr, const Token *startToken, const Token *endToken); - /** Is there some possible alias for given expression */ bool possiblyAliased(const Token *expr, const Token *startToken) const; diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 2245dee99..158bcac04 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -408,57 +408,6 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f } -const char *CheckMemoryLeak::functionArgAlloc(const Function *func, nonneg int targetpar, AllocType &allocType) const -{ - allocType = No; - - if (!func || !func->functionScope) - return ""; - - if (!Token::simpleMatch(func->retDef, "void")) - return ""; - - std::list::const_iterator arg = func->argumentList.begin(); - for (; arg != func->argumentList.end(); ++arg) { - if (arg->index() == targetpar-1) - break; - } - if (arg == func->argumentList.end()) - return ""; - - // Is ** - if (!arg->isPointer()) - return ""; - const Token* tok = arg->typeEndToken(); - tok = tok->previous(); - if (tok->str() != "*") - return ""; - - // Check if pointer is allocated. - bool realloc = false; - for (tok = func->functionScope->bodyStart; tok && tok != func->functionScope->bodyEnd; tok = tok->next()) { - if (tok->varId() == arg->declarationId()) { - if (Token::Match(tok->tokAt(-3), "free ( * %name% )")) { - realloc = true; - allocType = No; - } else if (Token::Match(tok->previous(), "* %name% =")) { - allocType = getAllocationType(tok->tokAt(2), arg->declarationId()); - if (allocType != No) { - if (realloc) - return "realloc"; - return "alloc"; - } - } else { - // unhandled variable usage: bailout - return ""; - } - } - } - - return ""; -} - - static bool notvar(const Token *tok, nonneg int varid) { if (!tok) diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index a61f3a598..6b3795ec8 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -145,9 +145,6 @@ public: /** What type of allocated memory does the given function return? */ AllocType functionReturnType(const Function* func, std::list *callstack = nullptr) const; - - /** Function allocates pointed-to argument (a la asprintf)? */ - const char *functionArgAlloc(const Function *func, nonneg int targetpar, AllocType &allocType) const; }; /// @} diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 46ad2057a..313f15c38 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2381,31 +2381,6 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* deref, const std::st "Possible dereference of an invalid iterator: $symbol. Make sure to check that the iterator is valid before dereferencing it - not after.", CWE825, Certainty::normal); } - -void CheckStl::readingEmptyStlContainer2() -{ - for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) { - for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) { - if (!tok->isName() || !tok->valueType()) - continue; - const Library::Container *container = tok->valueType()->container; - if (!container) - continue; - const ValueFlow::Value *value = tok->getContainerSizeValue(0); - if (!value) - continue; - if (value->isInconclusive() && !mSettings->certainty.isEnabled(Certainty::inconclusive)) - continue; - if (!value->errorSeverity() && !mSettings->severity.isEnabled(Severity::warning)) - continue; - if (Token::Match(tok, "%name% . %name% (")) { - if (container->getYield(tok->strAt(2)) == Library::Container::Yield::ITEM) - readingEmptyStlContainerError(tok,value); - } - } - } -} - void CheckStl::readingEmptyStlContainerError(const Token *tok, const ValueFlow::Value *value) { const std::string varname = tok ? tok->str() : std::string("var"); diff --git a/lib/checkstl.h b/lib/checkstl.h index c26c74f2b..33b40e3b8 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -178,9 +178,6 @@ public: */ void dereferenceErasedError(const Token* erased, const Token* deref, const std::string& itername, bool inconclusive); - /** @brief Reading from empty stl container (using valueflow) */ - void readingEmptyStlContainer2(); - /** @brief Look for loops that can replaced with std algorithms */ void useStlAlgorithm(); diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 79e3ced69..68036e197 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -76,16 +76,6 @@ void ImportProject::ignoreOtherConfigs(const std::string &cfg) } } -void ImportProject::ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType) -{ - for (std::list::iterator it = fileSettings.begin(); it != fileSettings.end();) { - if (it->platformType != cppcheck::Platform::Unspecified && it->platformType != platformType) - fileSettings.erase(it++); - else - ++it; - } -} - void ImportProject::FileSettings::setDefines(std::string defs) { while (defs.find(";%(") != std::string::npos) { diff --git a/lib/importproject.h b/lib/importproject.h index 6a6fa4173..faf63fa40 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -103,7 +103,6 @@ public: void ignorePaths(const std::vector &ipaths); void ignoreOtherConfigs(const std::string &cfg); - void ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType); Type import(const std::string &filename, Settings *settings=nullptr); protected: diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 79b5e3e6b..a8223bf91 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -559,36 +559,6 @@ void Preprocessor::preprocess(std::istream &istr, std::map= str.size() || // treat end of file as newline - str[i+1] == '\n' - ) - ) { - // Ignore space that has new line in either side of it - } else { - tmp.append(1, str[i]); - prev = str[i]; - } - } - - return tmp; -} - -void Preprocessor::preprocessWhitespaces(std::string &processedFile) -{ - // Replace all tabs with spaces.. - std::replace(processedFile.begin(), processedFile.end(), '\t', ' '); - - // Remove space characters that are after or before new line character - processedFile = removeSpaceNearNL(processedFile); -} - void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths) { (void)includePaths; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 59f759b4c..3a8d8e330 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -154,12 +154,6 @@ public: */ std::string getcode(const std::string &filedata, const std::string &cfg, const std::string &filename); - /** - * preprocess all whitespaces - * @param processedFile The data to be processed - */ - static void preprocessWhitespaces(std::string &processedFile); - /** * make sure empty configuration macros are not used in code. the given code must be a single configuration * @param cfg configuration @@ -184,14 +178,6 @@ private: static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList); - /** - * Remove space that has new line character on left or right side of it. - * - * @param str The string to be converted - * @return The string where space characters have been removed. - */ - static std::string removeSpaceNearNL(const std::string &str); - public: diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index cc8e86e67..7b769ff58 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1840,6 +1840,7 @@ void SymbolDatabase::validate() const if (mSettings->debugwarnings) { validateExecutableScopes(); } + // TODO //validateVariables(); } @@ -5329,17 +5330,6 @@ const Scope *SymbolDatabase::findScopeByName(const std::string& name) const //--------------------------------------------------------------------------- -Scope *Scope::findInNestedList(const std::string & name) -{ - for (Scope *scope: nestedList) { - if (scope->className == name) - return scope; - } - return nullptr; -} - -//--------------------------------------------------------------------------- - const Scope *Scope::findRecordInNestedList(const std::string & name) const { for (const Scope* scope: nestedList) { diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index ad02e15b3..923a5badf 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1128,12 +1128,6 @@ public: */ const Function *findFunction(const Token *tok, bool requireConst=false) const; - /** - * @brief find if name is in nested list - * @param name name of nested scope - */ - Scope *findInNestedList(const std::string & name); - const Scope *findRecordInNestedList(const std::string & name) const; Scope *findRecordInNestedList(const std::string & name) { return const_cast(const_cast(this)->findRecordInNestedList(name)); diff --git a/lib/token.cpp b/lib/token.cpp index a36a4a64f..ea072b08b 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1915,46 +1915,6 @@ const Token *Token::getValueTokenMaxStrLength() const return ret; } -static const Scope *getfunctionscope(const Scope *s) -{ - while (s && s->type != Scope::eFunction) - s = s->nestedIn; - return s; -} - -const Token *Token::getValueTokenDeadPointer() const -{ - const Scope * const functionscope = getfunctionscope(this->scope()); - - std::list::const_iterator it; - for (it = values().begin(); it != values().end(); ++it) { - // Is this a pointer alias? - if (!it->isTokValue() || (it->tokvalue && it->tokvalue->str() != "&")) - continue; - // Get variable - const Token *vartok = it->tokvalue->astOperand1(); - if (!vartok || !vartok->isName() || !vartok->variable()) - continue; - const Variable * const var = vartok->variable(); - if (var->isStatic() || var->isReference()) - continue; - if (!var->scope()) - return nullptr; // #6804 - if (var->scope()->type == Scope::eUnion && var->scope()->nestedIn == this->scope()) - continue; - // variable must be in same function (not in subfunction) - if (functionscope != getfunctionscope(var->scope())) - continue; - // Is variable defined in this scope or upper scope? - const Scope *s = this->scope(); - while ((s != nullptr) && (s != var->scope())) - s = s->nestedIn; - if (!s) - return it->tokvalue; - } - return nullptr; -} - static bool isAdjacent(const ValueFlow::Value& x, const ValueFlow::Value& y) { if (x.bound != ValueFlow::Value::Bound::Point && x.bound == y.bound) diff --git a/lib/token.h b/lib/token.h index 23b16c871..ba23cba17 100644 --- a/lib/token.h +++ b/lib/token.h @@ -863,7 +863,7 @@ public: void printOut(const char *title, const std::vector &fileNames) const; /** - * print out tokens + * print out tokens - used for debugging */ void printLines(int lines=5) const; @@ -1171,8 +1171,6 @@ public: const Token *getValueTokenMaxStrLength() const; const Token *getValueTokenMinStrSize(const Settings *settings) const; - const Token *getValueTokenDeadPointer() const; - /** Add token value. Return true if value is added. */ bool addValue(const ValueFlow::Value &value); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 12c56d669..d8a4b2260 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1966,9 +1966,6 @@ struct ValueFlowAnalyzer : Analyzer { virtual ProgramState getProgramState() const = 0; - virtual const ValueType* getValueType(const Token*) const { - return nullptr; - } virtual int getIndirect(const Token* tok) const { const ValueFlow::Value* value = getValue(tok); if (value) @@ -2640,10 +2637,6 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer { setupExprVarIds(val.tokvalue); } - virtual const ValueType* getValueType(const Token*) const OVERRIDE { - return expr->valueType(); - } - static bool nonLocal(const Variable* var, bool deref) { return !var || (!var->isLocal() && !var->isArgument()) || (deref && var->isArgument() && var->isPointer()) || var->isStatic() || var->isReference() || var->isExtern(); diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 546c9dd0e..eb56b123d 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -130,6 +130,7 @@ private: TEST_CASE(errorlistverbose2); TEST_CASE(ignorepathsnopath); + // TODO // Disabling these tests since they use relative paths to the // testrunner executable. //TEST_CASE(ignorepaths1); @@ -974,8 +975,8 @@ private: ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]); ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]); } - */ - void ignorepaths4() { + + void ignorepaths4() { REDIRECT; const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"}; CmdLineParser parser(&settings); @@ -983,8 +984,8 @@ private: ASSERT_EQUALS(2, parser.getIgnoredPaths().size()); ASSERT_EQUALS("src/", parser.getIgnoredPaths()[0]); ASSERT_EQUALS("module/", parser.getIgnoredPaths()[1]); - } - /* + } + void ignorefilepaths1() { REDIRECT; const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"}; @@ -993,15 +994,16 @@ private: ASSERT_EQUALS(1, parser.getIgnoredPaths().size()); ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]); } - */ - void ignorefilepaths2() { + + void ignorefilepaths2() { REDIRECT; const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"}; CmdLineParser parser(&settings); ASSERT(parser.parseFromArgs(3, argv)); ASSERT_EQUALS(1, parser.getIgnoredPaths().size()); ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]); - } + } + */ void checkconfig() { REDIRECT;