bluetooth: there may be no active local device

Which would lead to NULL dereference.
Related: update friendly name field on device change.

Fixes: #20137
Change-Id: I909501017f92952d97791ff88202ace12ac5623a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/11167
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: Máximo Castañeda <[email protected]>
Reviewed-by: Mohammed R. Attia <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Máximo Castañeda
2026-06-20 21:39:35 +00:00
parent 1a38566ed4
commit d865437549
@@ -83,7 +83,12 @@ BluetoothSettingsView::BluetoothSettingsView(const char* name)
B_TRANSLATE("Local devices found on system:"),
fLocalDevicesMenu);
fFriendlyName = new BTextControl("FriendlyName", B_TRANSLATE("Friendly Name:"), NULL,
new BMessage(kMsgSetFriendlyName));
if (ActiveLocalDevice != NULL) {
fFriendlyName->SetText(ActiveLocalDevice->GetFriendlyName());
fExtDeviceView->SetLocalDevice(ActiveLocalDevice);
fExtDeviceView->SetEnabled(true);
@@ -102,9 +107,6 @@ BluetoothSettingsView::BluetoothSettingsView(const char* name)
fClassMenu->SetValue(_GetClassForMenu());
fFriendlyName = new BTextControl("FriendlyName", B_TRANSLATE("Friendly Name:"),
ActiveLocalDevice->GetFriendlyName(), new BMessage(kMsgSetFriendlyName));
BLayoutBuilder::Grid<>(this, 0)
.SetInsets(10)
@@ -195,6 +197,9 @@ BluetoothSettingsView::MessageReceived(BMessage* message)
case kMsgSetFriendlyName:
{
if (ActiveLocalDevice == NULL)
break;
BString friendlyName = fFriendlyName->Text();
BMenuItem* item = fLocalDevicesMenu->FindItem(ActiveLocalDevice->GetFriendlyName());
@@ -286,6 +291,7 @@ BluetoothSettingsView::_MarkLocalDevice(LocalDevice* lDevice)
if (bdaddrUtils::Compare(lDevice->GetBluetoothAddress(), BDADDR_NULL))
return;
fFriendlyName->SetText(lDevice->GetFriendlyName());
fExtDeviceView->SetLocalDevice(lDevice);
fExtDeviceView->SetEnabled(true);
ActiveLocalDevice = lDevice;