diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index adcd48696..65731ed08 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -2108,7 +2108,7 @@ bool CheckBufferOverrun::analyseWholeProgram(const std::list & errors = true; } } - return errors; + return errors && errorLogger.hasErrors(); } unsigned int CheckBufferOverrun::sizeOfType(const Token *type) const diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index cb4e0c2c2..61d4f1556 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1606,6 +1606,5 @@ bool CheckUninitVar::analyseWholeProgram(const std::list &file } } - return foundErrors; + return foundErrors && errorLogger.hasErrors(); } - diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 030487c86..a0bbf1e0c 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -264,7 +264,7 @@ bool CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings */ } } - return errors; + return errors && errorLogger->hasErrors(); } void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger, diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 4758e1a57..74cca27f4 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -191,6 +191,8 @@ private: */ virtual void reportErr(const ErrorLogger::ErrorMessage &msg); + virtual bool hasErrors() const { return exitcode > 0; } + /** * @brief Information about progress is directed here. * diff --git a/lib/errorlogger.h b/lib/errorlogger.h index a778a91d2..8d7c20cbc 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -331,6 +331,12 @@ public: */ virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0; + /** + * Returns true if an error has been reported which should + * cause a non-zero cppcheck exit code. + */ + virtual bool hasErrors() const { return false; } + /** * Report progress to client * @param filename main file that is checked diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 275ce089b..4cc1862c4 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -77,11 +77,7 @@ private: // Check for unused functions.. CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this); checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings); - // check() returns error if and only if errout is not empty. - if (checkUnusedFunctions.check(this, settings)) - ASSERT(errout.str() != ""); - else - ASSERT_EQUALS("", errout.str()); + ASSERT(!checkUnusedFunctions.check(this, settings)); } void incondition() {