mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 05:53:52 +00:00
fix: a potential stack overflow error (#665)
* Fix a potential stack overflow error if nameless subcommands have fallthough * style: pre-commit.ci fixes Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
815553211b
commit
eba619fc68
@ -247,3 +247,8 @@ set_property(TEST retired_deprecated PROPERTY PASS_REGULAR_EXPRESSION "deprecate
|
|||||||
add_cli_exe(custom_parse custom_parse.cpp)
|
add_cli_exe(custom_parse custom_parse.cpp)
|
||||||
add_test(NAME cp_test COMMAND custom_parse --dv 1.7)
|
add_test(NAME cp_test COMMAND custom_parse --dv 1.7)
|
||||||
set_property(TEST cp_test PROPERTY PASS_REGULAR_EXPRESSION "called correct")
|
set_property(TEST cp_test PROPERTY PASS_REGULAR_EXPRESSION "called correct")
|
||||||
|
|
||||||
|
#------------------------------------------------
|
||||||
|
# This executable is for manual testing and is expected to change regularly
|
||||||
|
|
||||||
|
add_cli_exe(tester testEXE.cpp)
|
||||||
|
26
examples/testEXE.cpp
Normal file
26
examples/testEXE.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (c) 2017-2021, University of Cincinnati, developed by Henry Schreiner
|
||||||
|
// under NSF AWARD 1414736 and by the respective contributors.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// Code modified from https://github.com/CLIUtils/CLI11/issues/559
|
||||||
|
|
||||||
|
#include <CLI/CLI.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main(int argc, const char *argv[]) {
|
||||||
|
|
||||||
|
int logLevel{0};
|
||||||
|
CLI::App app{"Test App"};
|
||||||
|
|
||||||
|
app.add_option("-v", logLevel, "level");
|
||||||
|
|
||||||
|
auto subcom = app.add_subcommand("sub", "")->fallthrough();
|
||||||
|
subcom->preparse_callback([&app](size_t) { app.get_subcommand("sub")->add_option_group("group"); });
|
||||||
|
|
||||||
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
|
||||||
|
std::cout << "level: " << logLevel << std::endl;
|
||||||
|
}
|
@ -2732,13 +2732,16 @@ class App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If a subcommand, try the main command
|
|
||||||
if(parent_ != nullptr && fallthrough_)
|
// don't capture missing if this is a nameless subcommand and nameless subcommands can't fallthrough
|
||||||
return _get_fallthrough_parent()->_parse_arg(args, current_type);
|
|
||||||
// don't capture missing if this is a nameless subcommand
|
|
||||||
if(parent_ != nullptr && name_.empty()) {
|
if(parent_ != nullptr && name_.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a subcommand, try the main command
|
||||||
|
if(parent_ != nullptr && fallthrough_)
|
||||||
|
return _get_fallthrough_parent()->_parse_arg(args, current_type);
|
||||||
|
|
||||||
// Otherwise, add to missing
|
// Otherwise, add to missing
|
||||||
args.pop_back();
|
args.pop_back();
|
||||||
_move_to_missing(current_type, current);
|
_move_to_missing(current_type, current);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user