Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #13430 - added CLI option --max-template-recursion #7104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,13 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.maxCtuDepth = temp;
}

else if (std::strncmp(argv[i], "--max-template-recursion=", 25) == 0) {
int temp = 0;
if (!parseNumberArg(argv[i], 25, temp))
return Result::Fail;
mSettings.maxTemplateRecursion = temp;
}

// undocumented option for usage in Python tests to indicate that no build dir should be injected
else if (std::strcmp(argv[i], "--no-cppcheck-build-dir") == 0) {
mSettings.buildDir.clear();
Expand Down
16 changes: 16 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(debugLookupConfig);
TEST_CASE(debugLookupLibrary);
TEST_CASE(debugLookupPlatform);
TEST_CASE(maxTemplateRecursion);
TEST_CASE(maxTemplateRecursionMissingCount);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -2881,6 +2883,20 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(true, settings->debuglookupPlatform);
}

void maxTemplateRecursion() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--max-template-recursion=12", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS(12, settings->maxTemplateRecursion);
}

void maxTemplateRecursionMissingCount() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--max-template-recursion=", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parser->parseFromArgs(3, argv));
ASSERT_EQUALS("cppcheck: error: argument to '--max-template-recursion=' is not valid - not an integer.\n", logger->str());
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down
Loading