From bf41ac7e9f9ed44ac60622c1eaa8fe45e86759c1 Mon Sep 17 00:00:00 2001 From: edwinwu Date: Wed, 11 Aug 2021 22:13:45 -0700 Subject: [PATCH] Fixes the bluetooth MAC address not contained in ble_advertisement if invalid. Add the reserved bytes. PiperOrigin-RevId: 390290878 --- cpp/core/internal/ble_advertisement.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/core/internal/ble_advertisement.cc b/cpp/core/internal/ble_advertisement.cc index bd5f24d1..ba856d8e 100644 --- a/cpp/core/internal/ble_advertisement.cc +++ b/cpp/core/internal/ble_advertisement.cc @@ -238,11 +238,16 @@ BleAdvertisement::operator ByteArray() const { // clang-format on // The next 6 bytes are the bluetooth mac address. If bluetooth_mac_address - // is invalid or empty, we get back a empty byte array. + // is invalid or empty, we get back an empty byte array. auto bluetooth_mac_address_bytes{ BluetoothUtils::FromString(bluetooth_mac_address_)}; if (!bluetooth_mac_address_bytes.Empty()) { absl::StrAppend(&out, std::string(bluetooth_mac_address_bytes)); + } else { + // If bluetooth MAC address is invalid, then reserve the bytes. + auto fake_bt_mac_address_bytes = + ByteArray(BluetoothUtils::kBluetoothMacAddressLength); + absl::StrAppend(&out, std::string(fake_bt_mac_address_bytes)); } }