Skip to content

Commit

Permalink
bail out early on empty library in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jul 15, 2024
1 parent 48704ee commit 0ce4f3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

// --library
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
// TODO: bail out on empty library
std::list<std::string> libs = splitString(argv[i] + 10, ',');
for (auto& l : libs) {
if (l.empty()) {
mLogger.printError("empty library specified.");
return Result::Fail;
}
mSettings.libraries.emplace_back(std::move(l));
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,14 +2464,14 @@ class TestCmdlineParser : public TestFixture {
REDIRECT;
const char * const argv[] = {"cppcheck", "--library=posix,,gnu", "file.cpp"};
ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv));
ASSERT_EQUALS("cppcheck: Failed to load library configuration file ''. File not found\n", logger->str());
ASSERT_EQUALS("cppcheck: error: empty library specified.\n", logger->str());
}

void libraryMultipleEmpty2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--library=posix,gnu,", "file.cpp"};
ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv));
ASSERT_EQUALS("cppcheck: Failed to load library configuration file ''. File not found\n", logger->str());
ASSERT_EQUALS("cppcheck: error: empty library specified.\n", logger->str());
}

void suppressXml() {
Expand Down

0 comments on commit 0ce4f3b

Please sign in to comment.