MISRAC2012-Rule-14.4_c: compare against 0 or NULL

This commit is contained in:
Matthias Ringwald 2021-02-01 14:49:27 +01:00
parent da8f99ada5
commit 9305033e02
16 changed files with 52 additions and 52 deletions

View File

@ -675,7 +675,7 @@ static uint16_t handle_read_request2(att_connection_t * att_connection, uint8_t
// check security requirements
uint8_t error_code = att_validate_security(att_connection, ATT_READ, &it);
if (error_code) {
if (error_code != 0) {
return setup_error(response_buffer, request_type, handle, error_code);
}
@ -723,7 +723,7 @@ static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uin
// check security requirements
uint8_t error_code = att_validate_security(att_connection, ATT_READ, &it);
if (error_code) {
if (error_code != 0) {
return setup_error(response_buffer, request_type, handle, error_code);
}
@ -798,7 +798,7 @@ static uint16_t handle_read_multiple_request2(att_connection_t * att_connection,
// check security requirements
error_code = att_validate_security(att_connection, ATT_READ, &it);
if (error_code) break;
if (error_code != 0) break;
att_update_value_len(&it, att_connection->con_handle);
@ -814,7 +814,7 @@ static uint16_t handle_read_multiple_request2(att_connection_t * att_connection,
offset += bytes_copied;
}
if (error_code){
if (error_code != 0){
return setup_error(response_buffer, request_type, handle, error_code);
}
@ -989,7 +989,7 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t
}
// check security requirements
int error_code = att_validate_security(att_connection, ATT_WRITE, &it);
if (error_code) {
if (error_code != 0) {
return setup_error(response_buffer, request_type, handle, error_code);
}
att_persistent_ccc_cache(&it);
@ -999,7 +999,7 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t
if (error_code == ATT_ERROR_WRITE_RESPONSE_PENDING) return ATT_INTERNAL_WRITE_RESPONSE_PENDING;
#endif
if (error_code) {
if (error_code != 0) {
return setup_error(response_buffer, request_type, handle, error_code);
}
response_buffer[0] = ATT_WRITE_RESPONSE;
@ -1032,7 +1032,7 @@ static uint16_t handle_prepare_write_request(att_connection_t * att_connection,
}
// check security requirements
int error_code = att_validate_security(att_connection, ATT_WRITE, &it);
if (error_code) {
if (error_code != 0) {
return setup_error(response_buffer, request_type, handle, error_code);
}
@ -1091,7 +1091,7 @@ static uint16_t handle_execute_write_request(att_connection_t * att_connection,
if (att_prepare_write_error_code == ATT_ERROR_WRITE_RESPONSE_PENDING) return ATT_INTERNAL_WRITE_RESPONSE_PENDING;
#endif
// deliver queued errors
if (att_prepare_write_error_code){
if (att_prepare_write_error_code != 0){
att_clear_transaction_queue(att_connection);
uint8_t error_code = att_prepare_write_error_code;
uint16_t handle = att_prepare_write_error_handle;
@ -1408,7 +1408,7 @@ bool att_is_persistent_ccc(uint16_t handle){
uint16_t att_read_callback_handle_blob(const uint8_t * blob, uint16_t blob_size, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
btstack_assert(blob != NULL);
if (buffer){
if (buffer != NULL){
uint16_t bytes_to_copy = 0;
if (blob_size >= offset){
bytes_to_copy = btstack_min(blob_size - offset, buffer_size);

View File

@ -159,7 +159,7 @@ static void att_handle_value_indication_notify_client(uint8_t status, uint16_t c
static void att_emit_event_to_all(const uint8_t * event, uint16_t size){
// dispatch to app level handler
if (att_client_packet_handler){
if (att_client_packet_handler != NULL){
(*att_client_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t*) event, size);
}
@ -923,7 +923,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_
if (entry.att_handle != att_handle) continue;
// found matching entry
if (value){
if (value != 0){
// update
if (entry.value == value) {
log_info("CCC Index %u: Up-to-date", index);
@ -952,7 +952,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_
}
uint32_t tag_to_use = 0;
if (tag_for_empty){
if (tag_for_empty != 0){
tag_to_use = tag_for_empty;
} else if (tag_for_lowest_seq_nr){
tag_to_use = tag_for_lowest_seq_nr;
@ -1048,19 +1048,19 @@ static att_service_handler_t * att_service_handler_for_handle(uint16_t handle){
}
static att_read_callback_t att_server_read_callback_for_handle(uint16_t handle){
att_service_handler_t * handler = att_service_handler_for_handle(handle);
if (handler) return handler->read_callback;
if (handler != NULL) return handler->read_callback;
return att_server_client_read_callback;
}
static att_write_callback_t att_server_write_callback_for_handle(uint16_t handle){
att_service_handler_t * handler = att_service_handler_for_handle(handle);
if (handler) return handler->write_callback;
if (handler != NULL) return handler->write_callback;
return att_server_client_write_callback;
}
static btstack_packet_handler_t att_server_packet_handler_for_handle(uint16_t handle){
att_service_handler_t * handler = att_service_handler_for_handle(handle);
if (handler) return handler->packet_handler;
if (handler != NULL) return handler->packet_handler;
return att_client_packet_handler;
}
@ -1085,7 +1085,7 @@ static uint8_t att_validate_prepared_write(hci_con_handle_t con_handle){
att_service_handler_t * handler = (att_service_handler_t*) btstack_linked_list_iterator_next(&it);
if (!handler->write_callback) continue;
uint8_t error_code = (*handler->write_callback)(con_handle, 0, ATT_TRANSACTION_MODE_VALIDATE, 0, NULL, 0);
if (error_code) return error_code;
if (error_code != 0) return error_code;
}
if (!att_server_client_write_callback) return 0;
return (*att_server_client_write_callback)(con_handle, 0, ATT_TRANSACTION_MODE_VALIDATE, 0, NULL, 0);

View File

@ -117,7 +117,7 @@ void battery_service_server_init(uint8_t value){
void battery_service_server_set_battery_value(uint8_t value){
battery_value = value;
if (battery_value_client_configuration){
if (battery_value_client_configuration != 0){
battery_callback.callback = &battery_service_can_send_now;
battery_callback.context = (void*) (uintptr_t) battery_value_client_configuration_connection;
att_server_register_can_send_now_callback(&battery_callback, battery_value_client_configuration_connection);

View File

@ -71,7 +71,7 @@ static uint16_t nordic_spp_service_read_callback(hci_con_handle_t con_handle, ui
UNUSED(buffer_size);
if (attribute_handle == nordic_spp_tx_client_configuration_handle){
if (buffer){
if (buffer != NULL){
little_endian_store_16(buffer, 0, nordic_spp_tx_client_configuration_value);
}
return 2;
@ -89,7 +89,7 @@ static int nordic_spp_service_write_callback(hci_con_handle_t con_handle, uint16
}
if (attribute_handle == nordic_spp_tx_client_configuration_handle){
nordic_spp_tx_client_configuration_value = little_endian_read_16(buffer, 0);
if (nordic_spp_tx_client_configuration_value){
if (nordic_spp_tx_client_configuration_value != 0){
client_callback(con_handle, NULL, 0);
}
}

View File

@ -117,14 +117,14 @@ static uint16_t ublox_spp_service_read_callback(hci_con_handle_t con_handle, uin
if (!instance) return 0;
if (attribute_handle == instance->fifo_client_configuration_descriptor_handle){
if (buffer){
if (buffer != NULL){
little_endian_store_16(buffer, 0, instance->fifo_client_configuration_descriptor_value);
}
return 2;
}
if (attribute_handle == instance->credits_client_configuration_descriptor_handle){
if (buffer){
if (buffer != NULL){
little_endian_store_16(buffer, 0, instance->credits_client_configuration_descriptor_value);
}
return 2;

View File

@ -159,7 +159,7 @@ static gatt_client_t * gatt_client_get_context_for_handle(uint16_t handle){
// returns existing one, or tries to setup new one
static gatt_client_t * gatt_client_provide_context_for_handle(hci_con_handle_t con_handle){
gatt_client_t * gatt_client = gatt_client_get_context_for_handle(con_handle);
if (gatt_client) return gatt_client;
if (gatt_client != NULL) return gatt_client;
// bail if no such hci connection
hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);

View File

@ -291,9 +291,9 @@ void le_device_db_info(int index, int * addr_type, bd_addr_t addr, sm_key_t irk)
}
// setup return values
if (addr_type) *addr_type = entry.addr_type;
if (addr) (void)memcpy(addr, entry.addr, 6);
if (irk) (void)memcpy(irk, entry.irk, 16);
if (addr_type != NULL) *addr_type = entry.addr_type;
if (addr != NULL) (void)memcpy(addr, entry.addr, 6);
if (irk != NULL) (void)memcpy(irk, entry.irk, 16);
}
void le_device_db_encryption_set(int index, uint16_t ediv, uint8_t rand[8], sm_key_t ltk, int key_size, int authenticated, int authorized, int secure_connection){
@ -307,8 +307,8 @@ void le_device_db_encryption_set(int index, uint16_t ediv, uint8_t rand[8], sm_k
log_info("LE Device DB set encryption for %u, ediv x%04x, key size %u, authenticated %u, authorized %u, secure connection %u",
index, ediv, key_size, authenticated, authorized, secure_connection);
entry.ediv = ediv;
if (rand) (void)memcpy(entry.rand, rand, 8);
if (ltk) (void)memcpy(entry.ltk, ltk, 16);
if (rand != 0) (void)memcpy(entry.rand, rand, 8);
if (ltk != 0) (void)memcpy(entry.ltk, ltk, 16);
entry.key_size = key_size;
entry.authenticated = authenticated;
entry.authorized = authorized;
@ -331,13 +331,13 @@ void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm
// update user fields
log_info("LE Device DB encryption for %u, ediv x%04x, keysize %u, authenticated %u, authorized %u, secure connection %u",
index, entry.ediv, entry.key_size, entry.authenticated, entry.authorized, entry.secure_connection);
if (ediv) *ediv = entry.ediv;
if (rand) (void)memcpy(rand, entry.rand, 8);
if (ltk) (void)memcpy(ltk, entry.ltk, 16);
if (key_size) *key_size = entry.key_size;
if (authenticated) *authenticated = entry.authenticated;
if (authorized) *authorized = entry.authorized;
if (secure_connection) *secure_connection = entry.secure_connection;
if (ediv != NULL) *ediv = entry.ediv;
if (rand != NULL) (void)memcpy(rand, entry.rand, 8);
if (ltk != NULL) (void)memcpy(ltk, entry.ltk, 16);
if (key_size != NULL) *key_size = entry.key_size;
if (authenticated != NULL) *authenticated = entry.authenticated;
if (authorized != NULL) *authorized = entry.authorized;
if (secure_connection != NULL) *secure_connection = entry.secure_connection;
}
#ifdef ENABLE_LE_SIGNED_WRITE

View File

@ -1137,7 +1137,7 @@ static void sm_init_setup(sm_connection_t * sm_conn){
// query client for Legacy Pairing OOB data
setup->sm_have_oob_data = 0;
if (sm_get_oob_data) {
if (sm_get_oob_data != NULL) {
setup->sm_have_oob_data = (*sm_get_oob_data)(sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, setup->sm_tk);
}
@ -1146,7 +1146,7 @@ static void sm_init_setup(sm_connection_t * sm_conn){
memset(setup->sm_ra, 0, 16);
memset(setup->sm_rb, 0, 16);
if (setup->sm_have_oob_data && (sm_auth_req & SM_AUTHREQ_SECURE_CONNECTION)){
if (sm_get_sc_oob_data){
if (sm_get_sc_oob_data != NULL){
if (IS_RESPONDER(sm_conn->sm_role)){
setup->sm_have_oob_data = (*sm_get_sc_oob_data)(
sm_conn->sm_peer_addr_type,
@ -2690,7 +2690,7 @@ static void sm_run(void){
err = test_pairing_failure;
}
#endif
if (err){
if (err != 0){
setup->sm_pairing_failed_reason = err;
connection->sm_engine_state = SM_GENERAL_SEND_PAIRING_FAILED;
sm_trigger_run();
@ -3360,7 +3360,7 @@ static void sm_validate_er_ir(void){
static void sm_handle_random_result_ir(void *arg){
sm_persistent_keys_random_active = 0;
if (arg){
if (arg != NULL){
// key generated, store in tlv
int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','I','R'), sm_persistent_ir, 16u);
log_info("Generated IR key. Store in TLV status: %d", status);
@ -3379,7 +3379,7 @@ static void sm_handle_random_result_ir(void *arg){
static void sm_handle_random_result_er(void *arg){
sm_persistent_keys_random_active = 0;
if (arg){
if (arg != 0){
// key generated, store in tlv
int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16u);
log_info("Generated ER key. Store in TLV status: %d", status);
@ -3420,7 +3420,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
// setup IR/ER with TLV
btstack_tlv_get_instance(&sm_tlv_impl, &sm_tlv_context);
if (sm_tlv_impl){
if (sm_tlv_impl != NULL){
int key_size = sm_tlv_impl->get_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16u);
if (key_size == 16){
// ok, let's continue
@ -3874,7 +3874,7 @@ static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uin
}
#endif
if (err){
if (err != 0){
setup->sm_pairing_failed_reason = err;
sm_conn->sm_engine_state = SM_GENERAL_SEND_PAIRING_FAILED;
break;
@ -3984,7 +3984,7 @@ static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uin
// validate public key
err = btstack_crypto_ecc_p256_validate_public_key(setup->sm_peer_q);
if (err){
if (err != 0){
log_error("sm: peer public key invalid %x", err);
sm_pairing_error(sm_conn, SM_REASON_DHKEY_CHECK_FAILED);
break;

View File

@ -1282,7 +1282,7 @@ int btstack_crypto_ecc_p256_validate_public_key(const uint8_t * public_key){
mbedtls_ecp_point_free( & Q);
#endif
if (err){
if (err != 0){
log_error("public key invalid %x", err);
}
return err;

View File

@ -60,7 +60,7 @@ btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_linked_list_t
btstack_linked_item_t *lastItem = NULL;
btstack_linked_item_t *it;
for (it = *list; it != NULL; it = it->next){
if (it) {
if (it != NULL) {
lastItem = it;
}
}

View File

@ -104,7 +104,7 @@ int btstack_ring_buffer_write(btstack_ring_buffer_t * ring_buffer, uint8_t * dat
}
// copy second chunk
if (data_length) {
if (data_length != 0) {
(void)memcpy(&ring_buffer->storage[0], data, data_length);
ring_buffer->last_written_index += data_length;
}
@ -140,7 +140,7 @@ void btstack_ring_buffer_read(btstack_ring_buffer_t * ring_buffer, uint8_t * dat
}
// copy second chunk
if (data_length) {
if (data_length != 0) {
(void)memcpy(data, &ring_buffer->storage[0], data_length);
ring_buffer->last_read_index += data_length;
}

View File

@ -201,7 +201,7 @@ void btstack_slip_decoder_process(uint8_t input){
case SLIP_DECODER_ACTIVE:
switch(input){
case BTSTACK_SLIP_SOF:
if (decoder_pos){
if (decoder_pos != 0){
decoder_state = SLIP_DECODER_COMPLETE;
} else {
btstack_slip_decoder_reset();

View File

@ -383,7 +383,7 @@ int sscanf_bd_addr(const char * addr_string, bd_addr_t addr){
}
}
if (result){
if (result != 0){
bd_addr_copy(addr, buffer);
}
return result;

View File

@ -211,14 +211,14 @@ static void printf_packet(uint8_t packet_type, uint8_t in, uint8_t * packet, uin
printf("EVT <= ");
break;
case HCI_ACL_DATA_PACKET:
if (in) {
if (in != 0) {
printf("ACL <= ");
} else {
printf("ACL => ");
}
break;
case HCI_SCO_DATA_PACKET:
if (in) {
if (in != 0) {
printf("SCO <= ");
} else {
printf("SCO => ");

View File

@ -425,7 +425,7 @@ static void hci_transport_h4_init(const void * transport_config){
static int hci_transport_h4_open(void){
// open uart driver
int res = btstack_uart->open();
if (res){
if (res != 0){
return res;
}

View File

@ -3091,7 +3091,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t
// check size
if (len < 8u) return 0u;
connection = hci_connection_for_handle(handle);
if (connection){
if (connection != NULL){
if (connection->role != HCI_ROLE_MASTER){
// reject command without notifying upper layer when not in master role
return 0;