From 58dbbb0cab398b250e74ae2ec3eba0c58355c485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 14 Apr 2011 18:02:01 +0200 Subject: [PATCH] Inconclusive checking: Report inconclusive errors with reportInconclusiveError. It takes the same parameters as reportError. --- cli/threadexecutor.cpp | 3 ++- lib/check.h | 34 +++++++++++++++++++++++++++------- lib/checkmemoryleak.cpp | 2 +- lib/checkunusedfunctions.cpp | 2 +- lib/cppcheck.cpp | 8 +++++--- lib/errorlogger.cpp | 20 +++++++++++++++----- lib/errorlogger.h | 19 +++---------------- lib/preprocessor.cpp | 10 ++++++---- lib/symboldatabase.cpp | 3 ++- lib/token.cpp | 3 ++- lib/tokenize.cpp | 33 ++++++++++++++++++++++----------- test/testerrorlogger.cpp | 18 +++++++++--------- 12 files changed, 95 insertions(+), 60 deletions(-) diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index f9ae2459e..46527a9da 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -254,7 +254,8 @@ unsigned int ThreadExecutor::check() const ErrorLogger::ErrorMessage errmsg(locations, Severity::error, oss.str(), - "cppcheckError"); + "cppcheckError", + false); _errorLogger.reportErr(errmsg); } } diff --git a/lib/check.h b/lib/check.h index 2d10fa3e6..2d7f5baee 100644 --- a/lib/check.h +++ b/lib/check.h @@ -128,6 +128,32 @@ protected: /** report an error */ void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) + { + reportError(callstack, severity, id, msg, false); + } + + /** report an inconclusive error */ + void reportInconclusiveError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg) + { + std::list callstack; + if (tok) + callstack.push_back(tok); + reportInconclusiveError(callstack, severity, id, msg); + } + + /** report an inconclusive error */ + void reportInconclusiveError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) + { + reportError(callstack, severity, id, msg, true); + } + + +private: + /** disabled assignment operator */ + void operator=(const Check &); + + /** report an error */ + void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, std::string msg, bool inconclusive) { std::list locationList; for (std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it) @@ -142,7 +168,7 @@ protected: locationList.push_back(loc); } - ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id); + ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id, inconclusive); if (_tokenizer && _tokenizer->getFiles() && !_tokenizer->getFiles()->empty()) errmsg.file0 = _tokenizer->getFiles()->at(0); if (_errorLogger) @@ -151,12 +177,6 @@ protected: reportError(errmsg); } - - -private: - /** disabled assignment operator */ - void operator=(const Check &); - }; namespace std diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 780639f8d..5d0df311d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -352,7 +352,7 @@ void CheckMemoryLeak::reportErr(const std::list &callstack, Sever locations.push_back(loc); } - const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id); + const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id, false); if (errorLogger) errorLogger->reportErr(errmsg); diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index be2dce990..f7d5a4f6d 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -192,7 +192,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger, locationList.push_back(fileLoc); } - const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction"); + const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction", false); if (errorLogger) errorLogger->reportErr(errmsg); else diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c4e118a68..dd8ad23d0 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -164,7 +164,8 @@ unsigned int CppCheck::check() ErrorLogger::ErrorMessage errmsg(loclist, Severity::information, msg, - "toomanyconfigs"); + "toomanyconfigs", + false); _errorLogger.reportErr(errmsg); break; } @@ -333,7 +334,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) ErrorLogger::ErrorMessage errmsg(std::list(), Severity::error, error, - "pcre_compile"); + "pcre_compile", + false); reportErr(errmsg); } @@ -375,7 +377,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) summary = "found '" + str.substr(pos1, pos2 - pos1) + "'"; else summary = rule.summary; - ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id); + const ErrorLogger::ErrorMessage errmsg(callStack, Severity::fromString(rule.severity), summary, rule.id, false); // Report error reportErr(errmsg); diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index a32874113..b8a07dc10 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -26,10 +26,10 @@ ErrorLogger::ErrorMessage::ErrorMessage() :_severity(Severity::none) { - + _inconclusive = false; } -ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id) +ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) { // locations for this error message _callStack = callStack; @@ -42,6 +42,8 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list &callStack // set the message id _id = id; + + _inconclusive = inconclusive; } void ErrorLogger::ErrorMessage::setmsg(const std::string &msg) @@ -68,6 +70,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const std::ostringstream oss; oss << _id.length() << " " << _id; oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity); + oss << (_inconclusive ? "12 inconclusive" : ""); oss << _shortMessage.length() << " " << _shortMessage; oss << _verboseMessage.length() << " " << _verboseMessage; oss << _callStack.size() << " "; @@ -84,6 +87,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) { + _inconclusive = false; _callStack.clear(); std::istringstream iss(data); std::vector results; @@ -101,6 +105,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) temp.append(1, c); } + if (temp == "inconclusive") + { + _inconclusive = true; + break; + } + results.push_back(temp); if (results.size() == 4) break; @@ -205,7 +215,7 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const if (version == 1) { // No inconclusive messages in the xml version 1 - if (Severity::toString(_severity).compare(0,12,"inconclusive")==0) + if (_inconclusive) return ""; xml << " callStack; callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line)); - reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression")); + reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false)); } } diff --git a/lib/errorlogger.h b/lib/errorlogger.h index cde411176..bf2c01b1d 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -88,13 +88,7 @@ public: * Debug message. * Debug-mode message useful for the developers. */ - debug, - - /** inconclusive error */ - inconclusive_error, - - /** inconclusive warning */ - inconclusive_warning + debug }; static std::string toString(SeverityType severity) @@ -117,10 +111,6 @@ public: return "information"; case debug: return "debug"; - case inconclusive_error: - return "inconclusive error"; - case inconclusive_warning: - return "inconclusive warning"; }; return "???"; } @@ -144,10 +134,6 @@ public: return information; if (severity == "debug") return debug; - if (severity == "inconclusive error") - return inconclusive_error; - if (severity == "inconclusive warning") - return inconclusive_warning; return none; } }; @@ -202,7 +188,7 @@ public: }; - ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id); + ErrorMessage(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive); ErrorMessage(); /** @@ -229,6 +215,7 @@ public: std::list _callStack; Severity::SeverityType _severity; std::string _id; + bool _inconclusive; /** source file (not header) */ std::string file0; diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 1ae484866..caa0a6e7f 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -53,7 +53,8 @@ void Preprocessor::writeError(const std::string &fileName, const unsigned int li errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, Severity::error, errorText, - errorType)); + errorType, + false)); } static unsigned char readChar(std::istream &istr) @@ -1370,7 +1371,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const if (_errorLogger && _settings && _settings->debugwarnings) { std::list locationList; - const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug"); + const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "unhandled configuration: " + *it, "debug", false); _errorLogger->reportErr(errmsg); } @@ -1765,7 +1766,8 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const _errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, Severity::error, msg, - "preprocessorErrorDirective")); + "preprocessorErrorDirective", + false)); } Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str) @@ -1963,7 +1965,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line // currently a debug-message. const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug; const std::string id = userheader ? "missingInclude" : "debug"; - ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id); + ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false); errmsg.file0 = file0; _errorLogger->reportErr(errmsg); } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index f1c4f4f99..afc5c2dda 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1209,7 +1209,8 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, msg, - "debug"); + "debug", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); else diff --git a/lib/token.cpp b/lib/token.cpp index f5ade68c5..5c4804ed6 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -482,7 +482,8 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid) const ErrorLogger::ErrorMessage errmsg(locationList, Severity::error, "Internal error. Token::Match called with varid 0.", - "cppcheckError"); + "cppcheckError", + false); Check::reportError(errmsg); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0922f0c5e..11f5005be 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -489,7 +489,8 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons Severity::style, std::string(type + " '" + tok2->str() + "' hides typedef with same name"), - "variableHidingTypedef"); + "variableHidingTypedef", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -515,7 +516,8 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2, Severity::style, std::string(type + " '" + tok2->str() + "' forward declaration unnecessary, already declared"), - "unnecessaryForwardDeclaration"); + "unnecessaryForwardDeclaration", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -751,7 +753,8 @@ void Tokenizer::unsupportedTypedef(const Token *tok) const const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "Failed to parse \'" + str.str() + "\'. The checking continues anyway.", - "debug"); + "debug", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -2950,7 +2953,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok, const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "simplifyTemplates: bailing out", - "debug"); + "debug", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -3059,7 +3063,8 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok, const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "Failed to instantiate template. The checking continues anyway.", - "debug"); + "debug", + false); _errorLogger->reportErr(errmsg); } @@ -6807,7 +6812,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign const ErrorLogger::ErrorMessage errmsg(locationList, Severity::debug, "simplifyKnownVariables: bailing out (variable="+tok3->str()+", value="+value+")", - "debug"); + "debug", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -7698,7 +7704,8 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const Severity::style, std::string(type + " '" + tok2->str() + "' hides enumerator with same name"), - "variableHidingEnum"); + "variableHidingEnum", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -8337,7 +8344,8 @@ void Tokenizer::syntaxError(const Token *tok) const ErrorLogger::ErrorMessage errmsg(locationList, Severity::error, "syntax error", - "syntaxError"); + "syntaxError", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -8364,7 +8372,8 @@ void Tokenizer::syntaxError(const Token *tok, char c) "when these macros are defined: '" + _configuration + "'.", - "syntaxError"); + "syntaxError", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -8386,7 +8395,8 @@ void Tokenizer::cppcheckError(const Token *tok) const const ErrorLogger::ErrorMessage errmsg(locationList, Severity::error, "Analysis failed. If the code is valid then please report this failure.", - "cppcheckError"); + "cppcheckError", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); @@ -9667,7 +9677,8 @@ void Tokenizer::removeUnnecessaryQualification() const ErrorLogger::ErrorMessage errmsg(locationList, Severity::portability, "Extra qualification \'" + tok->str() + "::\' unnecessary and considered an error by many compilers.", - "portability"); + "portability", + false); if (_errorLogger) _errorLogger->reportErr(errmsg); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 27f54491f..868fc7179 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -67,7 +67,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.verboseMessage()); @@ -82,7 +82,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage()); @@ -97,7 +97,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage()); @@ -112,7 +112,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage()); @@ -127,7 +127,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("", msg.toXML(false,1)); @@ -140,7 +140,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); ASSERT_EQUALS("", ErrorLogger::ErrorMessage::getXMLFooter(1)); ASSERT_EQUALS("", msg.toXML(true,1)); @@ -153,7 +153,7 @@ private: loc.line = 5; std::list locs; locs.push_back(loc); - ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId"); + ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); std::string header("\n\n"); header += " locs; locs.push_back(loc); - // Error message - ErrorMessage msg(locs, Severity::inconclusive_error, "Programming error", "errorId"); + // Inconclusive error message + ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true); // Don't save inconclusive messages if the xml version is 1 ASSERT_EQUALS("", msg.toXML(false, 1));