cppcheck.cpp: only call `getFileInfo()` if necessary (#4510)

This commit is contained in:
Oliver Stöneberg 2022-09-27 20:04:35 +02:00 committed by GitHub
parent b9e07e918e
commit 10426f6707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 14 deletions

View File

@ -971,8 +971,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
mExitCode=1; // e.g. reflect a syntax error
}
if (!mSettings.buildDir.empty()) {
mAnalyzerInformation.setFileInfo("CheckUnusedFunctions", checkUnusedFunctions.analyzerInfo());
mAnalyzerInformation.close();
}
// In jointSuppressionReport mode, unmatched suppressions are
// collected after all files are processed
@ -1039,21 +1041,28 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
// TODO: Use CTU for Clang analysis
return;
if (mSettings.jobs == 1 || !mSettings.buildDir.empty()) {
// Analyse the tokens..
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);
if (fi1) {
if (mSettings.jobs == 1)
mFileInfo.push_back(fi1);
if (!mSettings.buildDir.empty())
mAnalyzerInformation.setFileInfo("ctu", fi1->toString());
}
for (const Check *check: Check::instances()) {
Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings);
if (fi != nullptr) {
if (mSettings.jobs == 1)
mFileInfo.push_back(fi);
if (!mSettings.buildDir.empty())
mAnalyzerInformation.setFileInfo(check->name(), fi->toString());
}
}
}
executeRules("normal", tokenizer);
}
@ -1535,6 +1544,7 @@ void CppCheck::reportErr(const ErrorMessage &msg)
if (std::find(mErrorList.begin(), mErrorList.end(), errmsg) != mErrorList.end())
return;
if (!mSettings.buildDir.empty())
mAnalyzerInformation.reportErr(msg, mSettings.verbose);
const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage();