summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-03-31 04:02:23 +0330
committerAndreas Kling <kling@serenityos.org>2023-03-31 06:55:46 +0200
commit83cb73a0452c39cbaf26b0c1d05ed5a219af8d24 (patch)
treee47bd1233083037b0bcf98d79d7a8c4399be620d /Userland/Libraries/LibCore
parent1173adb90a41870a9379a0eb4ec8e21119591ceb (diff)
downloadserenity-83cb73a0452c39cbaf26b0c1d05ed5a219af8d24.zip
LibCore: Don't assume ArgsParser arguments are non-empty
This was fine before as the last entry was a null string (which could be printed), but we no longer use C-style sentinel-terminated arrays for arguments.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/ArgsParser.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp
index 4f1f6f4a0c..30eb89bccb 100644
--- a/Userland/Libraries/LibCore/ArgsParser.cpp
+++ b/Userland/Libraries/LibCore/ArgsParser.cpp
@@ -27,13 +27,20 @@ ArgsParser::ArgsParser()
bool ArgsParser::parse(Span<StringView> arguments, FailureBehavior failure_behavior)
{
- auto fail = [this, name = arguments[0], failure_behavior] {
+ auto fail_impl = [this, failure_behavior](StringView name) {
if (failure_behavior == FailureBehavior::PrintUsage || failure_behavior == FailureBehavior::PrintUsageAndExit)
print_usage(stderr, name);
if (failure_behavior == FailureBehavior::Exit || failure_behavior == FailureBehavior::PrintUsageAndExit)
exit(1);
};
+ if (arguments.is_empty()) {
+ fail_impl("<exe>"sv);
+ return false;
+ }
+
+ auto fail = [name = arguments[0], &fail_impl] { fail_impl(name); };
+
OptionParser parser;
Vector<OptionParser::Option> long_options;