From 60afb1d1b44762868e4ac97e2a3eae106e70e3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Nov 2017 17:22:37 +0100 Subject: WX: Fix argument parsing Manually convert each argument to a UTF-8 std::string, because the implicit conversion for wxCmdLineArgsArray to char** calls ToAscii (which is obviously undesired). Fixes https://bugs.dolphin-emu.org/issues/10274 --- Source/Core/UICommon/CommandLineParse.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'Source/Core/UICommon/CommandLineParse.cpp') diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index 236cd86ba2..e8cdc6b3b6 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -105,17 +105,29 @@ std::unique_ptr CreateParser(ParserOptions options) return parser; } -optparse::Values& ParseArguments(optparse::OptionParser* parser, int argc, char** argv) +static void AddConfigLayer(const optparse::Values& options) { - optparse::Values& options = parser->parse_args(argc, argv); - const std::list& config_args = options.all("config"); - if (config_args.size()) + if (!config_args.empty()) { Config::AddLayer(std::make_unique( config_args, static_cast(options.get("video_backend")), static_cast(options.get("audio_emulation")))); } +} + +optparse::Values& ParseArguments(optparse::OptionParser* parser, int argc, char** argv) +{ + optparse::Values& options = parser->parse_args(argc, argv); + AddConfigLayer(options); + return options; +} + +optparse::Values& ParseArguments(optparse::OptionParser* parser, + const std::vector& arguments) +{ + optparse::Values& options = parser->parse_args(arguments); + AddConfigLayer(options); return options; } } -- cgit v1.2.3 From 653977cec758514027a0c73937b781f60c18ced9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Nov 2017 18:14:43 +0100 Subject: UICommon: Fix unsafe usage of optparse::Values::all The const-qualified all() member method triggers undefined behaviour if the option passed to it is not set. --- Source/Core/UICommon/CommandLineParse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/UICommon/CommandLineParse.cpp') diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index e8cdc6b3b6..1ca4bb90e8 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -107,9 +107,9 @@ std::unique_ptr CreateParser(ParserOptions options) static void AddConfigLayer(const optparse::Values& options) { - const std::list& config_args = options.all("config"); - if (!config_args.empty()) + if (options.is_set_by_user("config")) { + const std::list& config_args = options.all("config"); Config::AddLayer(std::make_unique( config_args, static_cast(options.get("video_backend")), static_cast(options.get("audio_emulation")))); -- cgit v1.2.3 From 05c8d229afc3d88f4c368a648e96b049ccd2fba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 26 Nov 2017 18:24:01 +0100 Subject: Config: Handle unknown system strings better Currently, a simple typo in the system name will trigger an assert message that complains about a "programming error". This is not user friendly and misleading. So this changes GetSystemFromName to return an std::optional, which allows for callers to check whether the system exists and handle failures better. --- Source/Core/UICommon/CommandLineParse.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Source/Core/UICommon/CommandLineParse.cpp') diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index 1ca4bb90e8..683738479f 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -40,8 +41,12 @@ public: std::getline(buffer, section, '.'); std::getline(buffer, key, '='); std::getline(buffer, value, '='); - Config::System system = Config::GetSystemFromName(system_str); - m_values.emplace_back(std::make_tuple(Config::ConfigLocation{system, section, key}, value)); + const std::optional system = Config::GetSystemFromName(system_str); + if (system) + { + m_values.emplace_back( + std::make_tuple(Config::ConfigLocation{*system, section, key}, value)); + } } } -- cgit v1.2.3