diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 181551e05f6..74bece05329 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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); @@ -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()); } @@ -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 errors; if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, fileIndex, hash, errors)) { while (!errors.empty()) { diff --git a/lib/cppcheck.h b/lib/cppcheck.h index d56d7fa6b4f..57b75a32613 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -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 diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 59b9ed835fa..a7c30580700 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -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 lg(mSuppressionsSync); out << " " << std::endl; for (const Suppression &suppression : mSuppressions) { + if (suppression.isInline && !suppression.fileName.empty() && !filePath.empty() && filePath != suppression.fileName) + continue; out << "