Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,9 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
}
errmsg.file0 = file0;

if (obj.count("hash")>0)
errmsg.hash = obj["hash"].get<std::int64_t>();

mErrorLogger.reportErr(errmsg);
}
}
Expand Down
14 changes: 6 additions & 8 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const std::set<std::string> ErrorLogger::mCriticalErrorIds{
};

ErrorMessage::ErrorMessage()
: severity(Severity::none), cwe(0U), certainty(Certainty::normal), hash(0)
: severity(Severity::none), cwe(0U), certainty(Certainty::normal)
{}

// TODO: id and msg are swapped compared to other calls
Expand All @@ -67,8 +67,7 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
file0(std::move(file1)),
severity(severity), // severity for this error message
cwe(0U),
certainty(certainty),
hash(0)
certainty(certainty)
{
// set the summary and verbose messages
setmsg(msg);
Expand All @@ -82,15 +81,14 @@ ErrorMessage::ErrorMessage(std::list<FileLocation> callStack, std::string file1,
file0(std::move(file1)),
severity(severity), // severity for this error message
cwe(cwe.id),
certainty(certainty),
hash(0)
certainty(certainty)
{
// set the summary and verbose messages
setmsg(msg);
}

ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity severity, std::string id, const std::string& msg, Certainty certainty)
: id(std::move(id)), severity(severity), cwe(0U), certainty(certainty), hash(0)
: id(std::move(id)), severity(severity), cwe(0U), certainty(certainty)
{
// Format callstack
for (auto it = callstack.cbegin(); it != callstack.cend(); ++it) {
Expand Down Expand Up @@ -125,7 +123,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token

setmsg(msg);

hash = 0; // calculateWarningHash(list, hashWarning.str());
// hash = calculateWarningHash(list, hashWarning.str());
}

ErrorMessage::ErrorMessage(ErrorPath errorPath, const TokenList *tokenList, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
Expand Down Expand Up @@ -158,7 +156,7 @@ ErrorMessage::ErrorMessage(ErrorPath errorPath, const TokenList *tokenList, Seve

setmsg(msg);

hash = 0; // calculateWarningHash(tokenList, hashWarning.str());
// hash = calculateWarningHash(tokenList, hashWarning.str());
}

ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
Expand Down
2 changes: 1 addition & 1 deletion lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CPPCHECKLIB ErrorMessage {
std::string guideline;

/** Warning hash */
std::size_t hash;
std::size_t hash{};

/** set short and verbose messages */
void setmsg(const std::string &msg);
Expand Down
5 changes: 5 additions & 0 deletions lib/sarifreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ picojson::array SarifReport::serializeResults() const
message["text"] = picojson::value(finding.shortMessage());
res["message"] = picojson::value(message);
res["ruleId"] = picojson::value(finding.id);
if (finding.hash != 0) {
picojson::object partialFingerprints;
partialFingerprints["hash/v1"] = picojson::value(std::to_string(finding.hash));
res["partialFingerprints"] = picojson::value(partialFingerprints);
}
results.emplace_back(res);
}
return results;
Expand Down
19 changes: 18 additions & 1 deletion test/cli/premium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,21 @@
assert exitcode == 0
assert stdout.startswith('Cppcheck ') # check for product name - TODO: should be "Cppcheck Premium"
assert '--premium=' in stdout, stdout # check for premium option
assert 'cppchecksolutions.com' in stdout, stdout # check for premium help link
assert 'cppchecksolutions.com' in stdout, stdout # check for premium help link


def test_hash(tmpdir):
# Trac 14225 - warnings with hash
test_file = os.path.join(tmpdir, 'test.c')
addon_file = os.path.join(tmpdir, 'premiumaddon.py')

with open(test_file, 'wt') as f:
f.write('void foo();\n')

args = [f"--addon={addon_file}", '--xml', test_file]

with open(addon_file, 'wt') as f:
f.write('print(\'{"addon":"a","column":1,"errorId":"id","extra":"","file":"test.c","hash":123,"linenr":1,"message":"bug","severity":"error"}\')')

_, _, stderr = cppcheck(args)
assert '<error id="a-id" severity="error" msg="bug" verbose="bug" hash="123" ' in stderr