Skip to content

Commit 87d32f1

Browse files
committed
fix clang-tidy and duplicates
1 parent 46b3715 commit 87d32f1

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎cli/cppcheckexecutor.cpp‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,30 +363,31 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
363363
supprlist.addSuppression(std::move(s));
364364
}
365365

366-
const auto getCfgs = [&](const std::string &sourcefile) {
367-
std::vector<std::string> cfgs;
366+
using AnalyzerInfoId = std::pair<std::string, std::size_t>;
367+
const auto getAnalyzerInfoIds = [&](const std::string &sourcefile) {
368+
std::vector<AnalyzerInfoId> ids;
368369
for (const FileSettings &fs : fileSettings) {
369370
if (fs.file.spath() == Path::simplifyPath(sourcefile))
370-
cfgs.push_back(fs.cfg);
371+
ids.emplace_back(fs.cfg, fs.file.fsFileId());
371372
}
372-
if (cfgs.empty())
373-
cfgs.emplace_back();
374-
return cfgs;
373+
if (ids.empty())
374+
ids.emplace_back("", 0);
375+
return ids;
375376
};
376377

377-
const auto reportErrorsFn = [&](const std::string &sourcefile, const std::vector<std::string> &cfgs, std::size_t fsFileId, const std::vector<ErrorMessage> &errors) -> bool {
378+
const auto reportErrorsFn = [&](const std::string &sourcefile, const std::vector<AnalyzerInfoId> &ids, const std::vector<ErrorMessage> &errors) -> bool {
378379
if (errors.empty())
379380
return false;
380381

381382
// TODO: what if sourcefile is empty?
382383

383-
for (const std::string &cfg : cfgs) {
384+
for (const AnalyzerInfoId &id : ids) {
384385
AnalyzerInformation analyzerInfo;
385386
// FIXME: this is a horrible hack
386387
// we need to "re-open" the file so we can add the unmatchedSuppression findings.
387388
// we cannot keep it open conditionally because the whole program analysis reads the XML.
388389
// re-ordering the code is also not an option because the unmatched suppression reporting needs to be run after all other checks.
389-
analyzerInfo.reopen(settings.buildDir, sourcefile, cfg, fsFileId);
390+
analyzerInfo.reopen(settings.buildDir, sourcefile, id.first, id.second);
390391

391392
for (const auto &errmsg : errors)
392393
analyzerInfo.reportErr(errmsg);
@@ -401,12 +402,12 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
401402

402403
for (auto i = files.cbegin(); i != files.cend(); ++i) {
403404
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(*i), settings.unmatchedSuppressionFilters);
404-
err |= reportErrorsFn(i->spath(), {""}, i->fsFileId(), errors);
405+
err |= reportErrorsFn(i->spath(), {{"", i->fsFileId()}}, errors);
405406
}
406407

407408
for (auto i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
408409
const std::vector<ErrorMessage> errors = getUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(i->file), settings.unmatchedSuppressionFilters);
409-
err |= reportErrorsFn(i->file.spath(), {i->cfg}, i->file.fsFileId(), errors);
410+
err |= reportErrorsFn(i->file.spath(), {{i->cfg, i->file.fsFileId()}}, errors);
410411
}
411412

412413
if (settings.inlineSuppressions) {
@@ -415,7 +416,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
415416
std::string sourcefile;
416417
if (!errmsg.callStack.empty())
417418
sourcefile = errmsg.callStack.cbegin()->getfile(false); // TODO: simplify path?
418-
err |= reportErrorsFn(sourcefile, getCfgs(sourcefile), 0, {errmsg});
419+
err |= reportErrorsFn(sourcefile, getAnalyzerInfoIds(sourcefile), {errmsg});
419420
}
420421
}
421422

@@ -424,7 +425,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
424425
std::string sourcefile;
425426
if (!errmsg.callStack.empty())
426427
sourcefile = errmsg.callStack.cbegin()->getfile(false); // TODO: simplify path?
427-
err |= reportErrorsFn(sourcefile, getCfgs(sourcefile), 0, {errmsg});
428+
err |= reportErrorsFn(sourcefile, getAnalyzerInfoIds(sourcefile), {errmsg});
428429
}
429430
return err;
430431
}

‎lib/cppcheck.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
18431843
std::string line;
18441844

18451845
if (!mSettings.buildDir.empty()) {
1846-
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.sfilename(), "", fileSettings.file.fsFileId());
1846+
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.sfilename(), fileSettings.cfg, fileSettings.file.fsFileId());
18471847
std::ofstream fcmd(analyzerInfoFile + ".clang-tidy-cmd");
18481848
fcmd << istr.str();
18491849
}

0 commit comments

Comments
 (0)