Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve
return {filename, files, outputList};
}

std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens) const
std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const std::string& filePath) const
{
std::ostringstream toolinfo;
toolinfo << (mSettings.cppcheckCfgProductName.empty() ? CPPCHECK_VERSION_STRING : mSettings.cppcheckCfgProductName);
Expand All @@ -867,7 +867,7 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simp
}
toolinfo << mSettings.premiumArgs;
// TODO: do we need to add more options?
mSuppressions.nomsg.dump(toolinfo);
mSuppressions.nomsg.dump(toolinfo, filePath);
return preprocessor.calculateHash(tokens, toolinfo.str());
}

Expand Down Expand Up @@ -1020,7 +1020,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string

if (analyzerInformation) {
// Calculate hash so it can be compared with old hash / future hashes
const std::size_t hash = calculateHash(preprocessor, tokens1);
const std::size_t hash = calculateHash(preprocessor, tokens1, file.spath());
std::list<ErrorMessage> errors;
if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) {
while (!errors.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class CPPCHECKLIB CppCheck {
* @param tokens Token list from preprocessed file.
* @return hash
*/
std::size_t calculateHash(const Preprocessor &preprocessor, const simplecpp::TokenList &tokens) const;
std::size_t calculateHash(const Preprocessor &preprocessor, const simplecpp::TokenList &tokens, const std::string& filePath = {}) const;

/**
* @brief Check a file using stream
Expand Down
4 changes: 3 additions & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,14 @@ bool SuppressionList::isSuppressed(const ::ErrorMessage &errmsg, const std::set<
return isSuppressed(SuppressionList::ErrorMessage::fromErrorMessage(errmsg, macroNames));
}

void SuppressionList::dump(std::ostream & out) const
void SuppressionList::dump(std::ostream & out, const std::string& filePath) const
{
std::lock_guard<std::mutex> lg(mSuppressionsSync);

out << " <suppressions>" << std::endl;
for (const Suppression &suppression : mSuppressions) {
if (!filePath.empty() && !suppression.fileName.empty() && filePath != suppression.fileName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the suppression could contain a pattern we need to use the matching logic of the suppressions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. There is only one suppression at a time, and we only care about inline suppressions.

continue;
out << " <suppression";
out << " errorId=\"" << ErrorLogger::toxml(suppression.errorId) << '"';
if (!suppression.fileName.empty())
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class CPPCHECKLIB SuppressionList {
* @brief Create an xml dump of suppressions
* @param out stream to write XML to
*/
void dump(std::ostream &out) const;
void dump(std::ostream &out, const std::string& filePath = {}) const;

/**
* @brief Returns list of unmatched local (per-file) suppressions.
Expand Down
Loading