Add null check before passing a char* to std::string::string()

PiperOrigin-RevId: 470812873
This commit is contained in:
hai007
2022-08-29 14:19:12 -07:00
committed by Copybara-Service
parent 408900e702
commit a7c967a034
@@ -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;