Skip to content

Commit

Permalink
add fuzz fail
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Jan 1, 2025
1 parent 7d23386 commit e414059
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/CLI/impl/Option_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
// this is an escape clause for odd strings
std::string nstrs{'['};
bool duplicated{true};
for(int ii = 2; ii < result.size() - 2; ii += 2) {
for(std::size_t ii = 2; ii < result.size() - 2; ii += 2) {
if(result[ii] == result[ii + 1]) {
nstrs.push_back(result[ii]);
} else {
Expand All @@ -677,6 +677,7 @@ CLI11_INLINE int Option::_add_result(std::string &&result, std::vector<std::stri
}
}
if(duplicated) {
nstrs.push_back(']');
res.push_back(std::move(nstrs));
++result_count;
return result_count;
Expand Down
15 changes: 15 additions & 0 deletions tests/OptionTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,21 @@ TEST_CASE_METHOD(TApp, "vectorSingleArg", "[optiontype]") {
CHECK("4" == extra);
}

TEST_CASE_METHOD(TApp, "vectorEmptyArg", "[optiontype]") {

std::vector<std::string> cv{ "test" };
app.add_option("-c", cv);
args = { "-c","test1", "[]"};

run();
CHECK(cv.size()==1);
args = { "-c","test1", "[[]]"};

run();
CHECK(cv.size()==2);
CHECK(cv[1]=="[]");
}

TEST_CASE_METHOD(TApp, "vectorDoubleArg", "[optiontype]") {

std::vector<std::pair<int, std::string>> cv;
Expand Down
Binary file added tests/fuzzFail/round_trip_custom3
Binary file not shown.

0 comments on commit e414059

Please sign in to comment.