Skip to content

Commit 7dc579a

Browse files
authored
fixed #13542 - added CLI option --emit-duplicates to allow showing duplicated findings (#7201)
1 parent a5cf0dd commit 7dc579a

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

cli/cmdlineparser.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
666666
else if (std::strcmp(argv[i], "--dump") == 0)
667667
mSettings.dump = true;
668668

669+
else if (std::strcmp(argv[i], "--emit-duplicates") == 0)
670+
mSettings.emitDuplicates = true;
671+
669672
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
670673
const std::string enable_arg = argv[i] + 9;
671674
const std::string errmsg = mSettings.addEnabled(enable_arg);

cli/cppcheckexecutor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ void StdLogger::reportErr(const ErrorMessage &msg)
623623
// TODO: we generate a different message here then we log below
624624
// TODO: there should be no need for verbose and default messages here
625625
// Alert only about unique errors
626-
if (!mShownErrors.insert(msg.toString(mSettings.verbose)).second)
626+
if (!mSettings.emitDuplicates && !mShownErrors.insert(msg.toString(mSettings.verbose)).second)
627627
return;
628628

629629
if (mSettings.outputFormat == Settings::OutputFormat::sarif)

cli/executor.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ bool Executor::hasToLog(const ErrorMessage &msg)
5050
if (errmsg.empty())
5151
return false;
5252

53+
if (mSettings.emitDuplicates)
54+
return true;
55+
5356
std::lock_guard<std::mutex> lg(mErrorListSync);
5457
if (mErrorList.emplace(std::move(errmsg)).second) {
5558
return true;

lib/cppcheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger
209209
// Alert only about unique errors.
210210
// This makes sure the errors of a single check() call are unique.
211211
// TODO: get rid of this? This is forwarded to another ErrorLogger which is also doing this
212-
if (!mErrorList.emplace(std::move(errmsg)).second)
212+
if (!mSettings.emitDuplicates && !mErrorList.emplace(std::move(errmsg)).second)
213213
return;
214214

215215
if (mAnalyzerInformation)

lib/settings.h

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
208208
/** @brief Is --dump given? */
209209
bool dump{};
210210

211+
/** @brief Do not filter duplicated errors. */
212+
bool emitDuplicates{};
213+
211214
/** @brief Name of the language that is enforced. Empty per default. */
212215
Standards::Language enforcedLang{};
213216

test/testcmdlineparser.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class TestCmdlineParser : public TestFixture {
421421
TEST_CASE(debugLookupPlatform);
422422
TEST_CASE(maxTemplateRecursion);
423423
TEST_CASE(maxTemplateRecursionMissingCount);
424+
TEST_CASE(emitDuplicates);
424425

425426
TEST_CASE(ignorepaths1);
426427
TEST_CASE(ignorepaths2);
@@ -2899,6 +2900,13 @@ class TestCmdlineParser : public TestFixture {
28992900
ASSERT_EQUALS("cppcheck: error: argument to '--max-template-recursion=' is not valid - not an integer.\n", logger->str());
29002901
}
29012902

2903+
void emitDuplicates() {
2904+
REDIRECT;
2905+
const char * const argv[] = {"cppcheck", "--emit-duplicates", "file.cpp"};
2906+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
2907+
ASSERT_EQUALS(true, settings->emitDuplicates);
2908+
}
2909+
29022910
void ignorepaths1() {
29032911
REDIRECT;
29042912
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)