Skip to content

Commit b87547c

Browse files
committed
only issue logChecker messages when necessary
1 parent a5a7dd7 commit b87547c

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
501501

502502
void StdLogger::writeCheckersReport(const Suppressions& supprs)
503503
{
504+
// TODO: only necessary when we actually issue a checkers report?
504505
if (!mCheckersFile.empty())
505506
{
506507
std::ofstream fout(mCheckersFile);
@@ -510,15 +511,14 @@ void StdLogger::writeCheckersReport(const Suppressions& supprs)
510511
}
511512
}
512513

513-
const bool summary = mSettings.safety || mSettings.severity.isEnabled(Severity::information);
514-
const bool xmlReport = mSettings.outputFormat == Settings::OutputFormat::xml && mSettings.xml_version == 3;
515-
const bool textReport = !mSettings.checkersReportFilename.empty();
514+
bool summary, xmlReport, textReport;
516515

517-
if (!summary && !xmlReport && !textReport)
516+
if (!mSettings.collectLogCheckers(&summary, &xmlReport, &textReport))
518517
return;
519518

520519
CheckersReport checkersReport(mSettings, mActiveCheckers);
521520

521+
// TODO: include in summary boolean
522522
const auto& suppressions = supprs.nomsg.getSuppressions();
523523
const bool summarySuppressed = std::any_of(suppressions.cbegin(), suppressions.cend(), [](const SuppressionList::Suppression& s) {
524524
return s.errorId == "checkersReport";

lib/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ErrorPath Check::getErrorPath(const Token* errtok, const ValueFlow::Value* value
130130

131131
void Check::logChecker(const char id[])
132132
{
133-
// TODO: only issue when we would actually use it later on
134-
reportError(nullptr, Severity::internal, "logChecker", id);
133+
if (!mSettings->buildDir.empty() || mSettings->collectLogCheckers())
134+
reportError(nullptr, Severity::internal, "logChecker", id);
135135
}
136136

lib/settings.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,3 +770,18 @@ bool Settings::unusedFunctionOnly()
770770
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
771771
return unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
772772
}
773+
774+
bool Settings::collectLogCheckers(bool* summary, bool* xmlReport, bool* textReport) const
775+
{
776+
const bool s = safety || severity.isEnabled(Severity::information);
777+
if (summary)
778+
*summary = s;
779+
const bool x = outputFormat == Settings::OutputFormat::xml && xml_version == 3;
780+
if (xmlReport)
781+
*xmlReport = x;
782+
const bool t = !checkersReportFilename.empty();
783+
if (textReport)
784+
*textReport = t;
785+
786+
return s || x || t;
787+
}

lib/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ class CPPCHECKLIB WARN_UNUSED Settings {
596596

597597
static bool unusedFunctionOnly();
598598

599+
bool collectLogCheckers(bool* summary = nullptr, bool* xmlReport = nullptr, bool* textReport = nullptr) const;
600+
599601
private:
600602
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity>, SimpleEnableGroup<Checks>> &groups);
601603
std::string applyEnabled(const std::string &str, bool enable);

test/cli/other_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,9 +4636,8 @@ def test_dui_include_absolute_missing(tmp_path): # #14675
46364636
]
46374637

46384638

4639-
@pytest.mark.xfail(strict=True) # TODO: should not report logChecker when not required
46404639
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4641-
def test_ipc_log_checker(tmp_path):
4640+
def test_ipc(tmp_path):
46424641
test_file = tmp_path / 'test.c'
46434642
with open(test_file, "w") as f:
46444643
f.write('void f() {}')
@@ -4648,6 +4647,7 @@ def test_ipc_log_checker(tmp_path):
46484647
'--debug-ipc',
46494648
'-j2',
46504649
'--executor=process',
4650+
'--no-cppcheck-build-dir',
46514651
str(test_file)
46524652
]
46534653

0 commit comments

Comments
 (0)