From 09d22a329c1b5c9406ff58fb16e44b3285e5e256 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 13 Nov 2018 23:40:16 +0000 Subject: [PATCH] BLE: Address special case when advertising payload size is 0. --- features/FEATURE_BLE/source/generic/GenericGap.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index e22a82fae2..fca2d63c5a 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -1872,8 +1872,10 @@ ble_error_t GenericGap::setAdvertisingData( &pal::Gap::set_extended_scan_response_data : &pal::Gap::set_extended_advertising_data; - // FIXME: Handle the case where the payload size is 0 - for (size_t i = 0, end = payload.size(); i < end; i += MAX_HCI_DATA_LENGTH) { + for (size_t i = 0, end = payload.size(); + (i < end) || (i == 0 && end == 0); + i += MAX_HCI_DATA_LENGTH) + { // select the operation based on the index op_t op(op_t::INTERMEDIATE_FRAGMENT); if (end < MAX_HCI_DATA_LENGTH) { @@ -2065,7 +2067,10 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload( typedef pal::advertising_fragment_description_t op_t; - for (size_t i = 0, end = payload.size(); i < end; i += MAX_HCI_DATA_LENGTH) { + for (size_t i = 0, end = payload.size(); + (i < end) || (i == 0 && end == 0); + i += MAX_HCI_DATA_LENGTH + ) { // select the operation based on the index op_t op(op_t::INTERMEDIATE_FRAGMENT); if (end < MAX_HCI_DATA_LENGTH) {