From 8eaf28b4ce5447e177a5a4fe0e63a08ea8bd9cad Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sat, 6 May 2023 08:17:24 +0200 Subject: [PATCH] LibGUI: Guard us from trying to slice an empty Arguments::strings This fixes an issue when we sometime pass in an empty Main::Arguments to GUI::Application::create(). Also, this mimics the behavior that Application::construct() had which only iterated over argv when more than one argument was passed to it. --- Userland/Libraries/LibGUI/Application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index 990c0a48c9..3d3fa8514b 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -93,8 +93,10 @@ ErrorOr> Application::create(Main::Arguments const& a if (getenv("GUI_DND_DEBUG")) application->m_dnd_debugging_enabled = true; - for (auto arg : arguments.strings.slice(1)) - TRY(application->m_args.try_append(arg)); + if (!arguments.strings.is_empty()) { + for (auto arg : arguments.strings.slice(1)) + TRY(application->m_args.try_append(arg)); + } application->m_tooltip_show_timer = TRY(Core::Timer::create_single_shot(700, [weak_application = application->make_weak_ptr()] { weak_application->request_tooltip_show();