Repository: CLIUtils/CLI11 (C++)

Issue:
Code that runs correctly with version 2.3.2 produces a seg-fault when built and executed with version 2.5.0.
Upgrading cli11 from version 2.3.2 to 2.5.0.
Code that previously functioned correctly when built using version 2.3.2 throws a seg-fault when built with version 2.5.0.
Reading through the release notes for the versions above 2.3.2 I can see no advisories or breaking-changes noted.

Here's a doctest test-case that demonstrates the issue.  The test runs correctly when built against 2.3.2 but generates a seg-fault when built against 2.5.0.  The code initialises the CLI app to handle a config file, but no config file is supplied on the input parameters.  The seg-fault is generated during the attempt to convert the config pointer returned by the get_config_ptr() API to a string via the 'as' API.

Replacing '**app.get_config_ptr()->as<<std::string>>()**' with '**app["--conf"]->as<<std::string>>()**' produces the same result (seg-fault with 2.5.0).

Using GCC12 compiler on Debian 12.

Am I doing something wrong, or is this a bug that has been introduced somewhere after version 2.3.2?


```
TEST_CASE("Crash demo") {
    const char* argv[] = {"cli", "spdlog", "--level=off"};

    CLI::App app;
    app.configurable()->allow_config_extras(false);
    app.set_config("--conf")->check(CLI::ExistingFile);

    std::string level;

    auto *command = app.add_subcommand("spdlog");
    command->add_option("--level", level, "Log level")->default_val("info");

    app.parse(3, argv);


    if (auto conf_filename = app.get_config_ptr()->as<std::string>(); !conf_filename.empty()) {
        std::cout << "Configuration filename: " << conf_filename << std::endl;
    } else {
        std::cout << "No configuration file used" << std::endl;
    }

    std::cout << "level is " << level << std::endl;
}
```


Discussion:
Interesting, I will take a look see if I can replicate it
I put in a fix in #1199.  Thank you for flagging this.  
No problem.  When is the next release due?
Don't really have a scheduled date, but there have been a couple bug fixes, that probably should go in a patch release soon.   



Patch:
diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp
index 5be2667d5..2a5eb4fea 100644
--- a/include/CLI/Option.hpp
+++ b/include/CLI/Option.hpp
@@ -681,7 +681,15 @@ class Option : public OptionBase<Option> {
         bool retval = false;
         if(current_option_state_ >= option_state::reduced || (results_.size() == 1 && validators_.empty())) {
             const results_t &res = (proc_results_.empty()) ? results_ : proc_results_;
-            retval = detail::lexical_conversion<T, T>(res, output);
+            if(!res.empty()) {
+                retval = detail::lexical_conversion<T, T>(res, output);
+            } else {
+                results_t res2;
+                res2.emplace_back();
+                proc_results_ = std::move(res2);
+                retval = detail::lexical_conversion<T, T>(proc_results_, output);
+            }
+
         } else {
             results_t res;
             if(results_.empty()) {


Test patch:
diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp
index 634890d77..2a5672627 100644
--- a/tests/ConfigFileTest.cpp
+++ b/tests/ConfigFileTest.cpp
@@ -4208,3 +4208,24 @@ TEST_CASE_METHOD(TApp, "RoundTripArrayFloat", "[config]") {
     CHECK(cv[0] == -1.0F);
     CHECK(cv[1] == 1.0F);
 }
+
+// Code from https://github.com/CLIUtils/CLI11/issues/1197
+TEST_CASE_METHOD(TApp, "CrashTest", "[config]") {
+    args = {"spdlog", "--level=off"};
+
+    app.configurable()->allow_config_extras(false);
+    app.set_config("--conf")->check(CLI::ExistingFile);
+
+    std::string level;
+
+    auto *command = app.add_subcommand("spdlog");
+    command->add_option("--level", level, "Log level")->default_val("info");
+
+    run();
+
+    auto *ptr = app.get_config_ptr();
+    std::string conf_filename;
+    CHECK_NOTHROW(conf_filename = ptr->as<std::string>());
+    CHECK(conf_filename.empty());
+    CHECK(level == "off");
+}
diff --git a/tests/HelpersTest.cpp b/tests/HelpersTest.cpp
index 5412545cd..651b92fd6 100644
--- a/tests/HelpersTest.cpp
+++ b/tests/HelpersTest.cpp
@@ -1516,6 +1516,14 @@ TEST_CASE("Types: LexicalConversionVectorDouble", "[helpers]") {
     CHECK(-3.54 == Approx(x[2]));
 }
 
+TEST_CASE("Types: LexicalConversionEmptyVectorDouble", "[helpers]") {
+    CLI::results_t input = {};
+    std::vector<double> x;
+    bool res = CLI::detail::lexical_conversion<std::vector<double>, std::vector<double>>(input, x);
+    CHECK(res);
+    CHECK(x.empty());
+}
+
 static_assert(!CLI::detail::is_tuple_like<std::vector<double>>::value, "vector should not be like a tuple");
 static_assert(CLI::detail::is_tuple_like<std::pair<double, double>>::value, "pair of double should be like a tuple");
 static_assert(CLI::detail::is_tuple_like<std::array<double, 4>>::value, "std::array<double,4> should be like a tuple");