Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 848ab236 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Fix loops iteration

The erase() already increment the iterator. If the loop additionally do
"it++", it will skip some elements, and might iterate over the end.

Test: compilation test
Change-Id: Ibd9c993d8e80d807f5d7bc920da36ee538477438
parent 8f7a231a
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -241,10 +241,13 @@ std::list<tGATT_HDL_LIST_ELEM>::iterator gatt_find_hdl_buffer_by_app_id(
 * ID.
 */
void gatt_free_srvc_db_buffer_app_id(tBT_UUID* p_app_id) {
  auto end_it = gatt_cb.hdl_list_info->end();
  for (auto it = gatt_cb.hdl_list_info->begin(); it != end_it; it++) {
  auto it = gatt_cb.hdl_list_info->begin();
  auto end = gatt_cb.hdl_list_info->end();
  while (it != end) {
    if (memcmp(p_app_id, &it->asgn_range.app_uuid128, sizeof(tBT_UUID)) == 0) {
      it = gatt_cb.hdl_list_info->erase(it);
    } else {
      it++;
    }
  }
}
@@ -1593,16 +1596,20 @@ bool gatt_remove_bg_dev_from_list(tGATT_REG* p_reg, BD_ADDR bd_addr) {
}
/** deregister all related back ground connetion device. */
void gatt_deregister_bgdev_list(tGATT_IF gatt_if) {
  auto it = gatt_cb.bgconn_dev.begin();
  auto end = gatt_cb.bgconn_dev.end();
  /* update the BG conn device list */
  for (auto it = gatt_cb.bgconn_dev.begin(); it != gatt_cb.bgconn_dev.end();
       it++) {
  while (it != end) {
    it->gatt_if.erase(gatt_if);
    if (it->gatt_if.size() == 0) {
    if (it->gatt_if.size()) {
      it++;
      continue;
    }

    BTM_BleUpdateBgConnDev(false, it->remote_bda);
    it = gatt_cb.bgconn_dev.erase(it);
  }
}
}

/*******************************************************************************
 *