diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 12eb2a8a67..8d63fe143e 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -230,6 +230,9 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const S for (size_t i = 0; i < k.size(); i++) { std::vector l = impl->split_string(k[i], '|', true); + if (l.size() < 3) + CV_Error_(Error::StsParseError, + ("invalid key description '{%s}': expected 'names | default | help'", k[i].c_str())); CommandLineParserParams p; p.keys = impl->split_string(l[0]); p.def_value = l[1]; diff --git a/modules/core/test/test_utils.cpp b/modules/core/test/test_utils.cpp index 6c6e6932d3..1a601a2651 100644 --- a/modules/core/test/test_utils.cpp +++ b/modules/core/test/test_utils.cpp @@ -36,6 +36,14 @@ TEST(CommandLineParser, testFailure) EXPECT_FALSE(parser.check()); } +TEST(CommandLineParser, testMalformedKeyDescription) +{ + const char* argv[] = {""}; + const int argc = 1; + EXPECT_THROW(cv::CommandLineParser(argc, argv, "{ a }"), cv::Exception); + EXPECT_THROW(cv::CommandLineParser(argc, argv, "{ a | 1 }"), cv::Exception); +} + TEST(CommandLineParser, testHas_noValues) { const char* argv[] = {"", "-h", "--info"};