MISRAC2012-Rule-14.4_b: compare iterator pointer against NULL in for loops

This commit is contained in:
Matthias Ringwald 2019-12-02 12:27:17 +01:00
parent 2baf01d2b2
commit a0da043fe7
4 changed files with 12 additions and 12 deletions

View File

@ -138,7 +138,7 @@ static void gatt_client_timeout_stop(gatt_client_t * peripheral){
static gatt_client_t * get_gatt_client_context_for_handle(uint16_t handle){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) gatt_client_connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) gatt_client_connections; it != NULL; it = it->next){
gatt_client_t * peripheral = (gatt_client_t *) it;
if (peripheral->con_handle == handle){
return peripheral;
@ -1074,7 +1074,7 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){
static void gatt_client_run(void){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) gatt_client_connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) gatt_client_connections; it != NULL; it = it->next){
gatt_client_t * peripheral = (gatt_client_t *) it;
if (!att_dispatch_client_can_send_now(peripheral->con_handle)) {
att_dispatch_client_request_can_send_now_event(peripheral->con_handle);

View File

@ -61,7 +61,7 @@ bool btstack_linked_list_empty(btstack_linked_list_t * list){
btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_linked_list_t * list){ // <-- find the last item in the list
btstack_linked_item_t *lastItem = NULL;
btstack_linked_item_t *it;
for (it = *list; it ; it = it->next){
for (it = *list; it != NULL; it = it->next){
if (it) {
lastItem = it;
}
@ -76,7 +76,7 @@ btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_linked_list_t
bool btstack_linked_list_add(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- add item to list
// check if already in list
btstack_linked_item_t *it;
for (it = *list; it ; it = it->next){
for (it = *list; it != NULL; it = it->next){
if (it == item) {
return false;
}
@ -90,7 +90,7 @@ bool btstack_linked_list_add(btstack_linked_list_t * list, btstack_linked_item_t
bool btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- add item to list as last element
// check if already in list
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list; it->next ; it = it->next){
for (it = (btstack_linked_item_t *) list; it->next != NULL ; it = it->next){
if (it->next == item) {
return false;
}
@ -103,7 +103,7 @@ bool btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_i
bool btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- remove item from list
if (!item) return false;
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) list; it ; it = it->next){
for (it = (btstack_linked_item_t *) list; it != NULL; it = it->next){
if (it->next == item){
it->next = item->next;
return true;
@ -118,7 +118,7 @@ bool btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_it
int btstack_linked_list_count(btstack_linked_list_t * list){
btstack_linked_item_t *it;
int counter = 0;
for (it = (btstack_linked_item_t *) list; it->next ; it = it->next) {
for (it = (btstack_linked_item_t *) list; it->next != NULL; it = it->next) {
counter++;
}
return counter;

View File

@ -86,7 +86,7 @@ void btstack_memory_pool_free(btstack_memory_pool_t *pool, void * block){
// raise error and abort if node already in list
node_t * it;
for (it = free_blocks->next; it ; it = it->next){
for (it = free_blocks->next; it != NULL; it = it->next){
if (it == node) {
log_error("btstack_memory_pool_free: block %p freed twice for pool %p", block, pool);
return;

View File

@ -439,7 +439,7 @@ static int hci_is_le_connection(hci_connection_t * connection){
static int nr_hci_connections(void){
int count = 0;
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL ; it = it->next){
count++;
}
return count;
@ -451,7 +451,7 @@ static int hci_number_free_acl_slots_for_connection_type(bd_addr_type_t address_
unsigned int num_packets_sent_le = 0;
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){
hci_connection_t * connection = (hci_connection_t *) it;
if (hci_is_le_connection(connection)){
num_packets_sent_le += connection->num_packets_sent;
@ -3533,7 +3533,7 @@ static void hci_run(void){
#endif
// send pending HCI commands
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){
hci_connection_t * connection = (hci_connection_t *) it;
switch(connection->state){
@ -4593,7 +4593,7 @@ uint8_t gap_connect(bd_addr_t addr, bd_addr_type_t addr_type){
// @assumption: only a single outgoing LE Connection exists
static hci_connection_t * gap_get_outgoing_connection(void){
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) hci_stack->connections; it ; it = it->next){
for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next){
hci_connection_t * conn = (hci_connection_t *) it;
if (!hci_is_le_connection(conn)) continue;
switch (conn->state){