From 6a7f1e4ae04a0fd2b5cd9c9bcd94321d0e1b1d7d Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:37:28 +0100 Subject: [PATCH 1/7] fixed some CLion "Unused global declaration" warnings --- cli/processexecutor.cpp | 2 +- gui/mainwindow.cpp | 1 - gui/projectfile.h | 6 ++++-- lib/checkother.cpp | 1 - lib/checkstl.cpp | 5 ----- lib/color.h | 6 +----- lib/cppcheck.h | 4 ---- lib/forwardanalyzer.cpp | 4 +--- lib/library.h | 2 +- lib/preprocessor.h | 7 +------ lib/programmemory.h | 2 -- lib/reverseanalyzer.cpp | 6 ------ lib/reverseanalyzer.h | 1 - lib/settings.h | 6 ------ lib/symboldatabase.cpp | 7 ------- lib/symboldatabase.h | 2 -- lib/token.cpp | 4 ---- lib/token.h | 1 - 18 files changed, 9 insertions(+), 58 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 994d5f8550b..a6c4e215080 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -68,7 +68,7 @@ ProcessExecutor::~ProcessExecutor() class PipeWriter : public ErrorLogger { public: - enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', REPORT_VERIFICATION='4', CHILD_END='5'}; + enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'}; explicit PipeWriter(int pipe) : mWpipe(pipe) {} diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 076ef2a63d3..c0c930663eb 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -71,7 +71,6 @@ #include #include -static const QString OnlineHelpURL("https://cppcheck.sourceforge.io/manual.html"); static const QString compile_commands_json("compile_commands.json"); static QString fromNativePath(const QString& p) { diff --git a/gui/projectfile.h b/gui/projectfile.h index 3fd3f6a08a1..e06f1fa450b 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -401,9 +401,11 @@ class ProjectFile : public QObject { QStringList getCheckUnknownFunctionReturn() const { return mCheckUnknownFunctionReturn; } - void setCheckUnknownFunctionReturn(const QStringList &s) { + /* + void setCheckUnknownFunctionReturn(const QStringList &s) { mCheckUnknownFunctionReturn = s; - } + } + */ /** Use Clang parser */ bool clangParser; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 156006b6f55..7a3ee24d8a2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -67,7 +67,6 @@ static const struct CWE CWE571(571U); // Expression is Always True static const struct CWE CWE672(672U); // Operation on a Resource after Expiration or Release static const struct CWE CWE628(628U); // Function Call with Incorrectly Specified Arguments static const struct CWE CWE683(683U); // Function Call With Incorrect Order of Arguments -static const struct CWE CWE686(686U); // Function Call With Incorrect Argument Type static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index ba12f466421..214cebf737b 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -453,11 +453,6 @@ static std::string getContainerName(const Token *containerToken) return ret; } -enum OperandPosition { - Left, - Right -}; - static bool isVector(const Token* tok) { if (!tok) diff --git a/lib/color.h b/lib/color.h index e2e46953306..16a30535fd9 100644 --- a/lib/color.h +++ b/lib/color.h @@ -32,11 +32,7 @@ enum class Color { FgGreen = 32, FgBlue = 34, FgMagenta = 35, - FgDefault = 39, - BgRed = 41, - BgGreen = 42, - BgBlue = 44, - BgDefault = 49 + FgDefault = 39 }; CPPCHECKLIB std::ostream& operator<<(std::ostream& os, const Color& c); diff --git a/lib/cppcheck.h b/lib/cppcheck.h index e161f94ae1e..d6ae066f173 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -123,10 +123,6 @@ class CPPCHECKLIB CppCheck : ErrorLogger { void tooManyConfigsError(const std::string &file, const int numberOfConfigurations); void purgedConfigurationMessage(const std::string &file, const std::string& configuration); - void dontSimplify() { - mSimplify = false; - } - /** Analyse whole program, run this after all TUs has been scanned. * This is deprecated and the plan is to remove this when * .analyzeinfo is good enough. diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 10bfb04fae0..784c44db160 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -49,7 +49,7 @@ struct OnExit { struct ForwardTraversal { enum class Progress { Continue, Break, Skip }; - enum class Terminate { None, Bail, Escape, Modified, Inconclusive, Conditional }; + enum class Terminate { None, Bail, Inconclusive }; ForwardTraversal(const ValuePtr& analyzer, const Settings& settings) : analyzer(analyzer), settings(settings), actions(Analyzer::Action::None), analyzeOnly(false), analyzeTerminate(false) {} @@ -333,8 +333,6 @@ struct ForwardTraversal { enum class Status { None, - Escaped, - Modified, Inconclusive, }; diff --git a/lib/library.h b/lib/library.h index 501fe1aade7..32e2e6e750a 100644 --- a/lib/library.h +++ b/lib/library.h @@ -250,7 +250,7 @@ class CPPCHECKLIB Library { }; struct RangeItemRecordTypeItem { std::string name; - int templateParameter; + int templateParameter; // TODO: use this }; std::string startPattern, startPattern2, endPattern, itEndPattern; std::map functions; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index de2973ba162..6d9f5500812 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -76,8 +76,7 @@ class CPPCHECKLIB Preprocessor { * Include file types. */ enum HeaderTypes { - NoHeader = 0, - UserHeader, + UserHeader = 1, SystemHeader }; @@ -173,10 +172,6 @@ class CPPCHECKLIB Preprocessor { static void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings); - void setFile0(const std::string &f) { - mFile0 = f; - } - /** * dump all directives present in source file */ diff --git a/lib/programmemory.h b/lib/programmemory.h index 27f9afb1d19..97c2f916f51 100644 --- a/lib/programmemory.h +++ b/lib/programmemory.h @@ -167,8 +167,6 @@ bool conditionIsTrue(const Token* condition, ProgramMemory pm, const Settings* s */ ProgramMemory getProgramMemory(const Token* tok, const Token* expr, const ValueFlow::Value& value, const Settings* settings); -ProgramMemory getProgramMemory(const Token *tok, const ProgramMemory::Map& vars); - ValueFlow::Value evaluateLibraryFunction(const std::unordered_map& args, const std::string& returnValue, const Settings* settings); diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp index 51615105073..7ec888a43eb 100644 --- a/lib/reverseanalyzer.cpp +++ b/lib/reverseanalyzer.cpp @@ -388,12 +388,6 @@ struct ReverseTraversal { } }; -void valueFlowGenericReverse(Token* start, const ValuePtr& a, const Settings& settings) -{ - ReverseTraversal rt{a, settings}; - rt.traverse(start); -} - void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr& a, const Settings& settings) { ReverseTraversal rt{a, settings}; diff --git a/lib/reverseanalyzer.h b/lib/reverseanalyzer.h index f42e0852a82..db80d3adab8 100644 --- a/lib/reverseanalyzer.h +++ b/lib/reverseanalyzer.h @@ -25,7 +25,6 @@ class Token; template class ValuePtr; -void valueFlowGenericReverse(Token* start, const ValuePtr& a, const Settings& settings); void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr& a, const Settings& settings); #endif diff --git a/lib/settings.h b/lib/settings.h index 56d99765983..a15349d6f17 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -61,12 +61,6 @@ class SimpleEnableGroup { void fill() { mFlags = 0xFFFFFFFF; } - void setEnabledAll(bool enabled) { - if (enabled) - fill(); - else - clear(); - } bool isEnabled(T flag) const { return (mFlags & (1U << (uint32_t)flag)) != 0; } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b93c7c67e0c..d2da93f0652 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4452,13 +4452,6 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope * className = nameTok->str(); } -bool Scope::hasDefaultConstructor() const -{ - return numConstructors > 0 && std::any_of(functionList.begin(), functionList.end(), [](const Function& func) { - return func.type == Function::eConstructor && func.argCount() == 0; - }); -} - AccessControl Scope::defaultAccess() const { switch (type) { diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a28a44efcfb..daab28b1736 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1177,8 +1177,6 @@ class CPPCHECKLIB Scope { functionMap.insert(make_pair(back->tokenDef->str(), back)); } - bool hasDefaultConstructor() const; - AccessControl defaultAccess() const; /** diff --git a/lib/token.cpp b/lib/token.cpp index 01a65e2c50e..2b5a281d6da 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2516,10 +2516,6 @@ Token* findTypeEnd(Token* tok) return tok; } -const Token* findTypeEnd(const Token* tok) { - return findTypeEnd(const_cast(tok)); -} - Token* findLambdaEndScope(Token* tok) { if (!Token::simpleMatch(tok, "[")) diff --git a/lib/token.h b/lib/token.h index 6b5536105a8..a0ee704132c 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1455,7 +1455,6 @@ class CPPCHECKLIB Token { }; Token* findTypeEnd(Token* tok); -const Token* findTypeEnd(const Token* tok); Token* findLambdaEndScope(Token* tok); const Token* findLambdaEndScope(const Token* tok); From cbaf3ba56049c820fd55a7b18826608d892e8a02 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:37:50 +0100 Subject: [PATCH 2/7] fixed some CLion "Not implemented function" warnings --- gui/resultstree.h | 8 -------- lib/checkuninitvar.h | 1 - lib/tokenize.h | 13 ------------- 3 files changed, 22 deletions(-) diff --git a/gui/resultstree.h b/gui/resultstree.h index 59cdb5e355e..ba7cad44932 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -344,14 +344,6 @@ protected slots: */ void startApplication(QStandardItem *target, int application = -1); - /** - * @brief Helper function to copy filename/full path to the clipboard - * - * @param target Error tree item to open - * @param fullPath Are we copying full path or only filename? - */ - void copyPathToClipboard(QStandardItem *target, bool fullPath); - /** * @brief Helper function returning the filename/full path of the error tree item \a target. * diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index c592d3fca9b..7eb5e554f1f 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -133,7 +133,6 @@ class CPPCHECKLIB CheckUninitVar : public Check { private: std::set mUninitDiags; Check::FileInfo* getFileInfo() const; - bool isUnsafeFunction(const Scope* scope, int argnr, const Token** tok) const; void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override { diff --git a/lib/tokenize.h b/lib/tokenize.h index 0ba1f9705bd..69f5d6b1ca3 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -158,13 +158,6 @@ class CPPCHECKLIB Tokenizer { nonneg int sizeOfType(const std::string& type) const; void simplifyDebug(); - /** - * Try to determine if function parameter is passed by value by looking - * at the function declaration. - * @param fpar token for function parameter in the function call - * @return true if the parameter is passed by value. if unsure, false is returned - */ - bool isFunctionParameterPassedByValue(const Token *fpar) const; /** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */ void simplifyAssignmentBlock(); @@ -548,12 +541,6 @@ class CPPCHECKLIB Tokenizer { */ void simplifyCPPAttribute(); - /** - * Replace strlen(str) - * @return true if any replacement took place, false else - * */ - bool simplifyStrlen(); - /** * Convert namespace aliases */ From 31fd7678ff8942c50da434645d509a557ef8367e Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:38:03 +0100 Subject: [PATCH 3/7] fixed some CLion "Unused struct" warnings --- lib/library.h | 9 --------- test/helpers.h | 16 ---------------- 2 files changed, 25 deletions(-) diff --git a/lib/library.h b/lib/library.h index 32e2e6e750a..542af659286 100644 --- a/lib/library.h +++ b/lib/library.h @@ -403,15 +403,6 @@ class CPPCHECKLIB Library { return arg ? arg->valid : emptyString; } - struct InvalidArgValue { - enum class Type {le, lt, eq, ge, gt, range} type; - std::string op1; - std::string op2; - bool isInt() const { - return MathLib::isInt(op1); - } - }; - const ArgumentChecks::IteratorInfo *getArgIteratorInfo(const Token *ftok, int argnr) const { const ArgumentChecks *arg = getarg(ftok, argnr); return arg && arg->iteratorInfo.it ? &arg->iteratorInfo : nullptr; diff --git a/test/helpers.h b/test/helpers.h index b90e096bd1b..b888bee9cb2 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -55,22 +55,6 @@ class givenACodeSampleToTokenize { }; -class SimpleSuppressor : public ErrorLogger { -public: - SimpleSuppressor(Settings &settings, ErrorLogger *next) - : settings(settings), next(next) {} - void reportOut(const std::string &outmsg, Color /*c*/ = Color::Reset) override { - next->reportOut(outmsg); - } - void reportErr(const ErrorMessage &msg) override { - if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg)) - next->reportErr(msg); - } -private: - Settings &settings; - ErrorLogger *next; -}; - class ScopedFile { public: ScopedFile(std::string name, const std::string &content, std::string path = ""); From ddccbf6efdf331ad34bc1ce0079bed70fee254a1 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:38:13 +0100 Subject: [PATCH 4/7] added TODO --- gui/projectfiledialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index c49e6dbe8a0..c508465a747 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -329,6 +329,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile) mUI->mComboBoxPlatform->setCurrentText(projectFile->getPlatform()); setSuppressions(projectFile->getSuppressions()); + // TODO // Human knowledge.. /* mUI->mListUnknownFunctionReturn->clear(); From c12f186c1c440208ea2c84bf1895e9cfb05e419d Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:23:59 +0100 Subject: [PATCH 5/7] removed unused parameter reported by CLion --- test/cfg/boost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cfg/boost.cpp b/test/cfg/boost.cpp index 25ef4ceebc5..ee6f77dd854 100644 --- a/test/cfg/boost.cpp +++ b/test/cfg/boost.cpp @@ -39,7 +39,7 @@ void valid_code(boost::function &pf_print_hello) pf_print_hello = boost::bind(print_hello); } -void ignoredReturnValue(char * buf) +void ignoredReturnValue() { // cppcheck-suppress ignoredReturnValue boost::math::round(1.5); From 4ec99ffefeb38d01cee673b65b3d71ebf7f286a4 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:26:37 +0100 Subject: [PATCH 6/7] fixed some CLion "Unused macro" warnings --- gui/common.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/gui/common.h b/gui/common.h index 1d10117cf74..e98d260e9cc 100644 --- a/gui/common.h +++ b/gui/common.h @@ -36,8 +36,6 @@ #define SETTINGS_WINDOW_MAXIMIZED "Window maximized" #define SETTINGS_WINDOW_WIDTH "Window width" #define SETTINGS_WINDOW_HEIGHT "Window height" -#define SETTINGS_LOG_VIEW_WIDTH "Log/View width" -#define SETTINGS_LOG_VIEW_HEIGHT "Log/View height" #define SETTINGS_MAINWND_SPLITTER_STATE "Mainwindow/Vertical splitter state" #define SETTINGS_CHECK_DIALOG_WIDTH "Check dialog width" #define SETTINGS_CHECK_DIALOG_HEIGHT "Check dialog height" @@ -101,7 +99,6 @@ #define SETTINGS_LAST_PROJECT_PATH "Last project path" #define SETTINGS_LAST_RESULT_PATH "Last result path" #define SETTINGS_LAST_SOURCE_PATH "Last source path" -#define SETTINGS_LAST_INCLUDE_PATH "Last include path" #define SETTINGS_LAST_APP_PATH "Last application path" #define SETTINGS_LAST_ANALYZE_FILES_FILTER "Last analyze files filter" From d2c332a3cd46a57b5a621a1b968c63ec2eb65e14 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Jan 2023 18:50:31 +0100 Subject: [PATCH 7/7] fixed some CLion "Condition is always true" warnings and a CLion "The value is never used" warning --- cli/cppcheckexecutorsig.cpp | 6 +----- gui/translationhandler.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index 102aae1d4fa..40a5b988e0b 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -120,7 +120,6 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) const Signalmap_t::const_iterator it=listofsignals.find(signo); const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str(); - bool printCallstack=true; // try to print a callstack? bool lowMem=false; // was low-memory condition detected? Be careful then! Avoid allocating much more memory then. bool unexpectedSignal=true; // unexpected indicates program failure bool terminate=true; // exit process/thread @@ -241,7 +240,6 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) unexpectedSignal=false; // legal usage: interrupt application via CTRL-C fputs("cppcheck received signal ", output); fputs(signame, output); - printCallstack=true; fputs(".\n", output); break; case SIGSEGV: @@ -277,11 +275,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) fputs(".\n", output); break; } - if (printCallstack) { #ifdef USE_UNIX_BACKTRACE_SUPPORT - print_stacktrace(output, true, -1, lowMem); + print_stacktrace(output, true, -1, lowMem); #endif - } if (unexpectedSignal) { fputs("\nPlease report this to the cppcheck developers!\n", output); } diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 59ab98d6475..481f33c2836 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -88,7 +88,7 @@ bool TranslationHandler::setLanguage(const QString &code) failure = true; } else { // Make sure there is a translator - if (!mTranslator && !failure) + if (!mTranslator) mTranslator = new QTranslator(this); //Load the new language @@ -106,18 +106,19 @@ bool TranslationHandler::setLanguage(const QString &code) else translationFile = appPath + "/" + mTranslations[index].mFilename + ".qm"; - if (!mTranslator->load(translationFile) && !failure) { + if (!mTranslator->load(translationFile)) { + failure = true; //If it failed, lets check if the default file exists if (!QFile::exists(translationFile)) { error = QObject::tr("Language file %1 not found!"); error = error.arg(translationFile); - failure = true; } - - //If file exists, there's something wrong with it - error = QObject::tr("Failed to load translation for language %1 from file %2"); - error = error.arg(mTranslations[index].mName); - error = error.arg(translationFile); + else { + //If file exists, there's something wrong with it + error = QObject::tr("Failed to load translation for language %1 from file %2"); + error = error.arg(mTranslations[index].mName); + error = error.arg(translationFile); + } } }