From a7c967a0341107ceb53501b5e7e07d4d92ee4ec1 Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 29 Aug 2022 14:17:24 -0700 Subject: [PATCH] Add null check before passing a char* to std::string::string() PiperOrigin-RevId: 470812873 --- .../platform/implementation/windows/bluetooth_adapter.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc index e5f147b6..491169a8 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter.cc @@ -249,13 +249,15 @@ std::string BluetoothAdapter::GetName() const { return *device_name_; } - std::string instance_id(GetGenericBluetoothAdapterInstanceID()); - - if (instance_id.empty()) { + char *_instance_id = GetGenericBluetoothAdapterInstanceID(); + if (_instance_id == nullptr) { NEARBY_LOGS(ERROR) << __func__ << ": Failed to get Generic Bluetooth Adapter InstanceID"; return std::string(); } + + std::string instance_id(_instance_id); + // Change radio module local name in registry HKEY hKey;