OSDN Git Service

Cleanup RawAddress usage
authorJakub Pawlowski <jpawlowski@google.com>
Wed, 16 Aug 2017 13:41:02 +0000 (06:41 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 17 Aug 2017 23:30:30 +0000 (16:30 -0700)
Use RawAddress::kLength instead of sizeof(RawAddress). When copying
value using memcpy, use "->address" instead of direct instance address.

Bug: 64726342
Change-Id: Iac7e5674f7e32b53162ab734c2251e65e9d4554c
Merged-In: Iac7e5674f7e32b53162ab734c2251e65e9d4554c
(cherry picked from commit 2e05f0dd4f3b33a0fdeb9a1c72a53cf14851e734)

btif/include/btif_debug_conn.h
btif/src/btif_core.cc
btif/src/btif_debug_conn.cc
btif/src/btif_hf_client.cc
btif/src/btif_storage.cc
device/include/interop.h
device/src/interop.cc
hci/src/hci_packet_parser.cc
service/hal/fake_bluetooth_interface.cc

index 532a09a..6ee374e 100644 (file)
@@ -28,7 +28,7 @@ typedef enum {
 } btif_debug_conn_state_t;
 
 // Report a connection state change
-void btif_debug_conn_state(const RawAddress bda,
+void btif_debug_conn_state(const RawAddress& bda,
                            const btif_debug_conn_state_t state,
                            const tGATT_DISCONN_REASON disconnect_reason);
 
index 1ac2ae6..8cc0430 100644 (file)
@@ -890,7 +890,7 @@ bt_status_t btif_get_adapter_property(bt_property_type_t type) {
       (type != BT_PROPERTY_BDNAME))
     return BT_STATUS_NOT_READY;
 
-  memset(&(req.read_req.bd_addr), 0, sizeof(RawAddress));
+  req.read_req.bd_addr = RawAddress::kEmpty;
   req.read_req.type = type;
 
   return btif_transfer_context(execute_storage_request,
@@ -1063,7 +1063,7 @@ bt_status_t btif_set_remote_device_property(RawAddress* remote_addr,
 
   if (!btif_is_enabled()) return BT_STATUS_NOT_READY;
 
-  memcpy(&(req.write_req.bd_addr), remote_addr, sizeof(RawAddress));
+  req.write_req.bd_addr = *remote_addr;
   memcpy(&(req.write_req.prop), property, sizeof(bt_property_t));
 
   return btif_transfer_context(execute_storage_remote_request,
index 869782f..9252a02 100644 (file)
@@ -63,7 +63,7 @@ static void next_event() {
   if (current_event == NUM_CONNECTION_EVENTS) current_event = 0;
 }
 
-void btif_debug_conn_state(const RawAddress bda,
+void btif_debug_conn_state(const RawAddress& bda,
                            const btif_debug_conn_state_t state,
                            const tGATT_DISCONN_REASON disconnect_reason) {
   next_event();
@@ -72,7 +72,7 @@ void btif_debug_conn_state(const RawAddress bda,
   evt->ts = time_gettimeofday_us();
   evt->state = state;
   evt->disconnect_reason = disconnect_reason;
-  memcpy(&evt->bda, &bda, sizeof(RawAddress));
+  evt->bda = bda;
 }
 
 void btif_debug_conn_dump(int fd) {
index 80a8d29..16af6ff 100644 (file)
@@ -249,7 +249,6 @@ btif_hf_client_cb_t* btif_hf_client_allocate_cb() {
   return NULL;
 }
 
-
 /*****************************************************************************
  *
  *   btif hf api functions (no context switch)
index 394d69e..9d4a84e 100644 (file)
@@ -456,8 +456,7 @@ static bt_status_t btif_in_fetch_bonded_devices(
           }
         }
         bt_linkkey_file_found = true;
-        memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++],
-               &bd_addr, sizeof(RawAddress));
+        p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr;
       } else {
         bt_linkkey_file_found = false;
       }
@@ -557,13 +556,13 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
       LOG_ERROR(LOG_TAG,
                 "%s: Controller not ready! Unable to return Bluetooth Address",
                 __func__);
-      memset(bd_addr, 0, sizeof(RawAddress));
+      *bd_addr = RawAddress::kEmpty;
       return BT_STATUS_FAIL;
     } else {
       LOG_ERROR(LOG_TAG, "%s: Controller ready!", __func__);
-      memcpy(bd_addr, controller->get_address(), sizeof(RawAddress));
+      *bd_addr = *controller->get_address();
     }
-    property->len = sizeof(RawAddress);
+    property->len = RawAddress::kLength;
     return BT_STATUS_SUCCESS;
   } else if (property->type == BT_PROPERTY_ADAPTER_BONDED_DEVICES) {
     btif_bonded_devices_t bonded_devices;
@@ -576,7 +575,7 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t* property) {
         __func__, bonded_devices.num_devices);
 
     if (bonded_devices.num_devices > 0) {
-      property->len = bonded_devices.num_devices * sizeof(RawAddress);
+      property->len = bonded_devices.num_devices * RawAddress::kLength;
       memcpy(property->val, bonded_devices.devices, property->len);
     }
 
@@ -852,7 +851,7 @@ bt_status_t btif_storage_load_bonded_devices(void) {
         bonded_devices.num_devices * sizeof(RawAddress);
     adapter_props[num_props].val = devices_list;
     for (i = 0; i < bonded_devices.num_devices; i++) {
-      memcpy(devices_list + i, &bonded_devices.devices[i], sizeof(RawAddress));
+      devices_list[i] = bonded_devices.devices[i];
     }
     num_props++;
 
@@ -1166,8 +1165,7 @@ static bt_status_t btif_in_fetch_bonded_ble_device(
 
     // Fill in the bonded devices
     if (device_added) {
-      memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++],
-             &bd_addr, sizeof(RawAddress));
+      p_bonded_devices->devices[p_bonded_devices->num_devices++] = bd_addr;
       btif_gatts_add_bonded_dev_from_nv(bd_addr);
     }
 
index cb7faed..96a3b9a 100644 (file)
@@ -110,7 +110,7 @@ bool interop_match_name(const interop_feature_t feature, const char* name);
 // Add a dynamic interop database entry for a device matching the first |length|
 // bytes of |addr|, implementing the workaround identified by |feature|.
 // |addr| may not be null.
-// |length| must be greater than 0 and less than sizeof(RawAddress).
+// |length| must be greater than 0 and less than RawAddress::kLength.
 // As |interop_feature_t| is not exposed in the public API, feature must be a
 // valid integer representing an option in the enum.
 void interop_database_add(const uint16_t feature, const RawAddress* addr,
index 78eb997..7b1fe59 100644 (file)
@@ -80,7 +80,7 @@ void interop_database_add(const uint16_t feature, const RawAddress* addr,
                           size_t length) {
   CHECK(addr);
   CHECK(length > 0);
-  CHECK(length < sizeof(RawAddress));
+  CHECK(length < RawAddress::kLength);
 
   interop_addr_entry_t* entry = static_cast<interop_addr_entry_t*>(
       osi_calloc(sizeof(interop_addr_entry_t)));
index 38f2011..e7ace27 100644 (file)
@@ -88,7 +88,7 @@ static void parse_read_local_supported_codecs_response(
 static void parse_read_bd_addr_response(BT_HDR* response,
                                         RawAddress* address_ptr) {
   uint8_t* stream = read_command_complete_header(
-      response, HCI_READ_BD_ADDR, sizeof(RawAddress) /* bytes after */);
+      response, HCI_READ_BD_ADDR, RawAddress::kLength /* bytes after */);
   CHECK(stream != NULL);
   STREAM_TO_BDADDR(*address_ptr, stream);
 
index 0ce6119..45fdca0 100644 (file)
@@ -115,8 +115,8 @@ void FakeBluetoothInterface::NotifyAdapterNamePropertyChanged(
 void FakeBluetoothInterface::NotifyAdapterAddressPropertyChanged(
     const RawAddress* address) {
   bt_property_t property;
-  property.len = sizeof(RawAddress);
-  property.val = (void*)address;
+  property.len = RawAddress::kLength;
+  property.val = (void*)address->address;
   property.type = BT_PROPERTY_BDADDR;
 
   NotifyAdapterPropertiesChanged(1, &property);