diff options
author | Linus Groh <mail@linusgroh.de> | 2021-01-30 13:00:59 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-30 13:42:15 +0100 |
commit | 5b43419a636699d71752de7cec91f6eb35ed50b5 (patch) | |
tree | 399c1d86f61cf6de2311c14f8711410546d04484 /Userland/Applications | |
parent | 9b0ca75f84666abb3c81b752d676d2056e399e1d (diff) | |
download | serenity-5b43419a636699d71752de7cec91f6eb35ed50b5.zip |
SystemMonitor: Handle PCIDB::Database::open() failure gracefully
No need to dereference the nullptr, let's just show raw IDs instead.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/SystemMonitor/main.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index ce9b2488df..bb06c236d7 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -498,6 +498,8 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab() auto& pci_table_view = self.add<GUI::TableView>(); auto db = PCIDB::Database::open(); + if (!db) + warnln("Couldn't open PCI ID database!"); Vector<GUI::JsonArrayModel::FieldSpec> pci_fields; pci_fields.empend( @@ -513,23 +515,23 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab() "Class", Gfx::TextAlignment::CenterLeft, [db](const JsonObject& object) { auto class_id = object.get("class").to_u32(); - String class_name = db->get_class(class_id); - return class_name == "" ? String::formatted("{:04x}", class_id) : class_name; + String class_name = db ? db->get_class(class_id) : nullptr; + return class_name.is_empty() ? String::formatted("{:04x}", class_id) : class_name; }); pci_fields.empend( "Vendor", Gfx::TextAlignment::CenterLeft, [db](const JsonObject& object) { auto vendor_id = object.get("vendor_id").to_u32(); - String vendor_name = db->get_vendor(vendor_id); - return vendor_name == "" ? String::formatted("{:02x}", vendor_id) : vendor_name; + String vendor_name = db ? db->get_vendor(vendor_id) : nullptr; + return vendor_name.is_empty() ? String::formatted("{:02x}", vendor_id) : vendor_name; }); pci_fields.empend( "Device", Gfx::TextAlignment::CenterLeft, [db](const JsonObject& object) { auto vendor_id = object.get("vendor_id").to_u32(); auto device_id = object.get("device_id").to_u32(); - String device_name = db->get_device(vendor_id, device_id); - return device_name == "" ? String::formatted("{:02x}", device_id) : device_name; + String device_name = db ? db->get_device(vendor_id, device_id) : nullptr; + return device_name.is_empty() ? String::formatted("{:02x}", device_id) : device_name; }); pci_fields.empend( "Revision", Gfx::TextAlignment::CenterRight, |