Skip to content

Commit 56124f0

Browse files
authored
Skip calculateWarningHash if we are not in bugHunting (#3047)
1 parent c94713c commit 56124f0

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

lib/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void Check::reportError(const ErrorMessage &errmsg)
4848

4949
void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, bool inconclusive)
5050
{
51-
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, inconclusive);
51+
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, inconclusive, mSettings ? mSettings->bugHunting : false);
5252
if (mErrorLogger)
5353
mErrorLogger->reportErr(errmsg);
5454
else
@@ -57,7 +57,7 @@ void Check::reportError(const std::list<const Token *> &callstack, Severity::Sev
5757

5858
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive)
5959
{
60-
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, inconclusive);
60+
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, inconclusive, mSettings ? mSettings->bugHunting : false);
6161
if (mErrorLogger)
6262
mErrorLogger->reportErr(errmsg);
6363
else

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severit
297297

298298
void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
299299
{
300-
const ErrorMessage errmsg(callstack, mTokenizer_ ? &mTokenizer_->list : nullptr, severity, id, msg, cwe, false);
300+
const ErrorMessage errmsg(callstack, mTokenizer_ ? &mTokenizer_->list : nullptr, severity, id, msg, cwe, false, mSettings_->bugHunting);
301301
if (mErrorLogger_)
302302
mErrorLogger_->reportErr(errmsg);
303303
else

lib/errorlogger.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
120120
}
121121

122122

123-
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive)
123+
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive, bool bugHunting)
124124
: id(id), incomplete(false), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
125125
{
126126
// Format callstack
@@ -142,10 +142,10 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
142142
hashWarning << std::hex << (tok ? tok->index() : 0) << " ";
143143
hashWarning << mShortMessage;
144144

145-
hash = calculateWarningHash(list, hashWarning.str());
145+
hash = bugHunting ? calculateWarningHash(list, hashWarning.str()) : 0;
146146
}
147147

148-
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive)
148+
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive, bool bugHunting)
149149
: id(id), incomplete(false), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
150150
{
151151
// Format callstack
@@ -174,7 +174,7 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
174174
hashWarning << std::hex << (e.first ? e.first->index() : 0) << " ";
175175
hashWarning << mShortMessage;
176176

177-
hash = calculateWarningHash(tokenList, hashWarning.str());
177+
hash = bugHunting ? calculateWarningHash(tokenList, hashWarning.str()) : 0;
178178
}
179179

180180
ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)

lib/errorlogger.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,16 @@ class CPPCHECKLIB ErrorMessage {
147147
const std::string& id,
148148
const std::string& msg,
149149
const CWE &cwe,
150-
bool inconclusive);
150+
bool inconclusive,
151+
bool bugHunting);
151152
ErrorMessage(const ErrorPath &errorPath,
152153
const TokenList *tokenList,
153154
Severity::SeverityType severity,
154155
const char id[],
155156
const std::string &msg,
156157
const CWE &cwe,
157-
bool inconclusive);
158+
bool inconclusive,
159+
bool bugHunting);
158160
ErrorMessage();
159161
explicit ErrorMessage(const tinyxml2::XMLElement * const errmsg);
160162

lib/exprengine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ namespace {
642642

643643
ErrorPath e = errorPath;
644644
e.push_back(ErrorPathItem(tok, text));
645-
ErrorMessage errmsg(e, &tokenizer->list, severity, id, text, cwe, inconclusive);
645+
ErrorMessage errmsg(e, &tokenizer->list, severity, id, text, cwe, inconclusive, true);
646646
errmsg.incomplete = incomplete;
647647
errmsg.function = functionName.empty() ? currentFunction : functionName;
648648
errorLogger->reportErr(errmsg);

0 commit comments

Comments
 (0)