Skip to content

Commit 0ce4f3b

Browse files
committed
bail out early on empty library in CLI
1 parent 48704ee commit 0ce4f3b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

cli/cmdlineparser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
870870

871871
// --library
872872
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
873-
// TODO: bail out on empty library
874873
std::list<std::string> libs = splitString(argv[i] + 10, ',');
875874
for (auto& l : libs) {
875+
if (l.empty()) {
876+
mLogger.printError("empty library specified.");
877+
return Result::Fail;
878+
}
876879
mSettings.libraries.emplace_back(std::move(l));
877880
}
878881
}

test/testcmdlineparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,14 +2464,14 @@ class TestCmdlineParser : public TestFixture {
24642464
REDIRECT;
24652465
const char * const argv[] = {"cppcheck", "--library=posix,,gnu", "file.cpp"};
24662466
ASSERT_EQUALS(false, parser->fillSettingsFromArgs(3, argv));
2467-
ASSERT_EQUALS("cppcheck: Failed to load library configuration file ''. File not found\n", logger->str());
2467+
ASSERT_EQUALS("cppcheck: error: empty library specified.\n", logger->str());
24682468
}
24692469

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

24772477
void suppressXml() {

0 commit comments

Comments
 (0)