From fedd08754604af418a5d6f8a8ef2c595529f866e Mon Sep 17 00:00:00 2001 From: Edwin Rijkee Date: Thu, 27 Jul 2023 16:38:52 +0200 Subject: [PATCH] NetworkSettings: Don't assert when there are no network adapters NetworkSettings normally filters out `loop` when populating its list of adapters. However, when checking if there aren't any adapters it did not take this into account. This causes it to crash later when trying to set the selected index of an empty combo box. This moves the check for no adapters to after filtering the list, so that shows the error message and exits. --- .../NetworkSettings/NetworkSettingsWidget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp b/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp index 27852dee3b..91acb0bc55 100644 --- a/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp +++ b/Userland/Applications/NetworkSettings/NetworkSettingsWidget.cpp @@ -77,12 +77,6 @@ ErrorOr NetworkSettingsWidget::setup() JsonParser parser(data); JsonValue proc_net_adapters_json = TRY(parser.parse()); - // FIXME: This should be done before creating a window. - if (proc_net_adapters_json.as_array().is_empty()) { - GUI::MessageBox::show_error(window(), "No network adapters found!"sv); - ::exit(1); - } - size_t selected_adapter_index = 0; size_t index = 0; proc_net_adapters_json.as_array().for_each([&](auto& value) { @@ -109,6 +103,12 @@ ErrorOr NetworkSettingsWidget::setup() index++; }); + // FIXME: This should be done before creating a window. + if (m_adapter_names.is_empty()) { + GUI::MessageBox::show_error(window(), "No network adapters found!"sv); + ::exit(1); + } + m_adapters_combobox->set_model(TRY(GUI::ItemListModel::try_create(m_adapter_names))); m_adapters_combobox->on_change = [this](DeprecatedString const& text, GUI::ModelIndex const&) { on_switch_adapter(text);