1
0
mirror of https://github.com/bluekitchen/btstack.git synced 2025-03-26 20:37:19 +00:00

use unsigned literals instead of clumsy casts in ad_parser.c and btstack_event.h

This commit is contained in:
Matthias Ringwald 2020-07-14 23:37:47 +02:00
parent 44c20b8a7b
commit 0dd3c6c3ef
3 changed files with 18 additions and 19 deletions

@ -63,18 +63,18 @@ void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_
bool ad_iterator_has_more(const ad_context_t * context){
// assert chunk_len and chunk_type are withing buffer
if ((context->offset + (uint8_t) 1) >= context->length) {
if ((context->offset + 1u) >= context->length) {
return false;
}
// assert chunk_len > 0
uint8_t chunk_len = context->data[context->offset];
if (chunk_len == (uint8_t) 0){
if (chunk_len == 0u){
return false;
}
// assert complete chunk fits into buffer
if ((context->offset + (uint8_t) 1 + chunk_len) > context->length) {
if ((context->offset + 1u + chunk_len) > context->length) {
return false;
}
return true;
@ -83,19 +83,19 @@ bool ad_iterator_has_more(const ad_context_t * context){
// pre: ad_iterator_has_more() == 1
void ad_iterator_next(ad_context_t * context){
uint8_t chunk_len = context->data[context->offset];
context->offset += (uint8_t) 1 + chunk_len;
context->offset += 1u + chunk_len;
}
uint8_t ad_iterator_get_data_len(const ad_context_t * context){
return context->data[context->offset] - (uint8_t) 1;
return context->data[context->offset] - 1u;
}
uint8_t ad_iterator_get_data_type(const ad_context_t * context){
return context->data[context->offset + (uint8_t) 1];
return context->data[context->offset + 1u];
}
const uint8_t * ad_iterator_get_data(const ad_context_t * context){
return &context->data[context->offset + (uint8_t) 2];
return &context->data[context->offset + 2u];
}
bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid16){
@ -112,7 +112,7 @@ bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t u
switch (data_type){
case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS:
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS:
for (i=0; (i + (uint8_t) 2) <= data_len; i+= (uint8_t) 2){
for (i=0u; (i + 2u) <= data_len; i+= 2u){
uint16_t uuid = (uint16_t) little_endian_read_16(data, (int) i);
if ( uuid == uuid16 ) {
return true;
@ -123,10 +123,10 @@ bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t u
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
uuid_add_bluetooth_prefix(ad_uuid128, uuid16);
reverse_128(ad_uuid128, uuid128_bt);
for (i=0; (i + (uint8_t) 16) <= data_len; i += (uint8_t) 16){
if (memcmp(uuid128_bt, &data[i], 16) == 0){
return true;
};
for (i=0u; (i + 16u) <= data_len; i += 16u){
if (memcmp(uuid128_bt, &data[i], 16) == 0){
return true;
};
}
break;
default:
@ -154,7 +154,7 @@ bool ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uin
switch (data_type){
case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS:
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS:
for (i = (uint8_t) 0; (i+ (uint8_t) 2) <= data_len; i += (uint8_t) 2){
for (i = 0u; (i+2u) <= data_len; i += 2u){
uint16_t uuid16 = little_endian_read_16(data, (int) i);
uuid_add_bluetooth_prefix(ad_uuid128, uuid16);
@ -166,7 +166,7 @@ bool ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uin
break;
case BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS:
for (i = (uint8_t) 0; (i + (uint8_t) 16) <= data_len; i += (uint8_t) 16){
for (i = 0u; (i + 16u) <= data_len; i += 16u){
if (memcmp(uuid128_le, &data[i], 16) == 0) {
return true;
}

@ -7254,7 +7254,7 @@ static inline const uint8_t * pbap_subevent_card_result_get_name(const uint8_t *
* @note: btstack_type J
*/
static inline uint8_t pbap_subevent_card_result_get_handle_len(const uint8_t * event){
return event[((uint8_t) 6) + event[5]];
return event[6u + event[5]];
}
/**
* @brief Get field handle from event PBAP_SUBEVENT_CARD_RESULT
@ -7263,7 +7263,7 @@ static inline uint8_t pbap_subevent_card_result_get_handle_len(const uint8_t * e
* @note: btstack_type V
*/
static inline const uint8_t * pbap_subevent_card_result_get_handle(const uint8_t * event){
return &event[((uint8_t) 6) + event[5] + ((uint8_t) 1)];
return &event[6u + event[5] + 1u];
}
/**

@ -1,4 +1,3 @@
# BlueKitchen GmbH (c) 2014
#!/usr/bin/env python3
import glob
@ -311,7 +310,7 @@ def create_events(events):
if last_variable_length_field_pos != '':
if offset_is_number:
# convert to string
offset = '((uint8_t) %u)' % offset
offset = '%uu' % offset
offset_is_number = 0
offset = offset + ' + event[%s]' % last_variable_length_field_pos
else:
@ -320,7 +319,7 @@ def create_events(events):
if offset_is_number:
offset += size_for_type(field_type)
else:
offset = offset + ' + ((uint8_t) %u)' % size_for_type(field_type)
offset = offset + ' + %uu' % size_for_type(field_type)
if is_le_event(event_group):
fout.write("#endif\n")
fout.write("\n")