From 505f1c302fb378f14d4d6a6833359f4948f47b23 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 19 Nov 2019 16:04:15 +0100 Subject: [PATCH] ISRAC2012-Rule-12.1: add suggested parentheses --- src/ble/sm.c | 8 ++++---- src/classic/hfp.c | 14 +++++++------- src/classic/hfp_ag.c | 20 ++++++++++---------- src/classic/hfp_hf.c | 28 ++++++++++++++-------------- src/classic/hfp_msbc.c | 2 +- src/classic/hsp_hs.c | 2 +- src/classic/rfcomm.c | 2 +- src/classic/sdp_client.c | 2 +- src/classic/sdp_util.c | 2 +- src/l2cap.c | 8 ++++---- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/ble/sm.c b/src/ble/sm.c index 20dbb485c..bbd0f197d 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -1665,7 +1665,7 @@ static void sm_sc_calculate_remote_confirm(sm_connection_t * sm_conn){ } static void sm_sc_prepare_dhkey_check(sm_connection_t * sm_conn){ - log_info("sm_sc_prepare_dhkey_check, DHKEY calculated %u", setup->sm_state_vars & SM_STATE_VAR_DHKEY_CALCULATED ? 1 : 0); + log_info("sm_sc_prepare_dhkey_check, DHKEY calculated %u", (setup->sm_state_vars & SM_STATE_VAR_DHKEY_CALCULATED) ? 1 : 0); if (setup->sm_state_vars & SM_STATE_VAR_DHKEY_CALCULATED){ sm_conn->sm_engine_state = SM_SC_W2_CALCULATE_F5_SALT; @@ -2021,8 +2021,8 @@ static void sm_run(void){ #ifdef ENABLE_LE_SECURE_CONNECTIONS // assert ec key is ready - if (sm_connection->sm_engine_state == SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED - || sm_connection->sm_engine_state == SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST){ + if ((sm_connection->sm_engine_state == SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED) + || (sm_connection->sm_engine_state == SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST)){ if (ec_key_generation_state == EC_KEY_GENERATION_IDLE){ sm_ec_generate_new_key(); } @@ -3315,7 +3315,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint // delete stored bonding on disconnect with authentication failure in ph0 if ((sm_conn->sm_role == 0) - && sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED + && (sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED) && (packet[2] == ERROR_CODE_AUTHENTICATION_FAILURE)){ le_device_db_remove(sm_conn->sm_le_db_index); } diff --git a/src/classic/hfp.c b/src/classic/hfp.c index ffa268275..02737473f 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -574,7 +574,7 @@ static int hfp_handle_failed_sco_connection(uint8_t status){ } log_info("(e)SCO Connection failed status 0x%02x", status); // invalid params / unspecified error - if ((status != 0x11) && (status != 0x1f) && status != 0x0D) return 0; + if ((status != 0x11) && (status != 0x1f) && (status != 0x0D)) return 0; switch (sco_establishment_active->link_setting){ case HFP_LINK_SETTINGS_D0: @@ -782,7 +782,7 @@ void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *pac status = rfcomm_event_channel_opened_get_status(packet); hfp_connection = get_hfp_connection_context_for_bd_addr(event_addr, local_role); - if (!hfp_connection || hfp_connection->state != HFP_W4_RFCOMM_CONNECTED) return; + if (!hfp_connection || (hfp_connection->state != HFP_W4_RFCOMM_CONNECTED)) return; if (status) { hfp_emit_slc_connection_event(hfp_connection, status, rfcomm_event_channel_opened_get_con_handle(packet), event_addr); @@ -894,7 +894,7 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){ return HFP_CMD_RING; } - if (isHandsFree && strncmp(line_buffer+offset, HFP_OK, strlen(HFP_OK)) == 0){ + if (isHandsFree && (strncmp(line_buffer+offset, HFP_OK, strlen(HFP_OK)) == 0)){ return HFP_CMD_OK; } @@ -987,11 +987,11 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){ return HFP_CMD_TRANSFER_AG_INDICATOR_STATUS; } - if (isHandsFree && strncmp(line_buffer+offset, HFP_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){ + if (isHandsFree && (strncmp(line_buffer+offset, HFP_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0)){ return HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR; } - if (!isHandsFree && strncmp(line_buffer+offset, HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){ + if (!isHandsFree && (strncmp(line_buffer+offset, HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0)){ return HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR; } @@ -1112,7 +1112,7 @@ void hfp_parse(hfp_connection_t * hfp_connection, uint8_t byte, int isHandsFree) // TODO: handle space inside word if ((byte == ' ') && (hfp_connection->parser_state > HFP_PARSER_CMD_HEADER)) return; - if ((byte == ',') && hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE){ + if ((byte == ',') && (hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE)){ if (hfp_connection->line_size == 0){ hfp_connection->line_buffer[0] = 0; hfp_connection->ignore_value = 1; @@ -1240,7 +1240,7 @@ void hfp_parse(hfp_connection_t * hfp_connection, uint8_t byte, int isHandsFree) } hfp_parser_next_state(hfp_connection, byte); - if (hfp_connection->resolve_byte && hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE){ + if (hfp_connection->resolve_byte && (hfp_connection->command == HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE)){ hfp_connection->resolve_byte = 0; hfp_connection->ignore_value = 1; parse_sequence(hfp_connection); diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index 1fe7486ce..d43633606 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -602,7 +602,7 @@ static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){ } // if AG is ringing, also start ringing on the HF if ((hfp_gsm_call_status() == HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS) && - hfp_gsm_callsetup_status() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS){ + (hfp_gsm_callsetup_status() == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS)){ hfp_ag_hf_start_ringing(hfp_connection); } } @@ -766,11 +766,11 @@ static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connectio } static int hfp_ag_run_for_audio_connection(hfp_connection_t * hfp_connection){ - if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED || - hfp_connection->state > HFP_W2_DISCONNECT_SCO) return 0; + if ((hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) || + (hfp_connection->state > HFP_W2_DISCONNECT_SCO)) return 0; - if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED && hfp_connection->release_audio_connection){ + if ((hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) && hfp_connection->release_audio_connection){ hfp_connection->state = HFP_W4_SCO_DISCONNECTED; hfp_connection->release_audio_connection = 0; gap_disconnect(hfp_connection->sco_handle); @@ -932,8 +932,8 @@ static void hfp_ag_hf_accept_call(hfp_connection_t * source){ while (btstack_linked_list_iterator_has_next(&it)){ hfp_connection_t * hfp_connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it); if (hfp_connection->local_role != HFP_ROLE_AG) continue; - if (hfp_connection->call_state != HFP_CALL_RINGING && - hfp_connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue; + if ((hfp_connection->call_state != HFP_CALL_RINGING) && + (hfp_connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING)) continue; hfp_ag_hf_stop_ringing(hfp_connection); if (hfp_connection == source){ @@ -985,8 +985,8 @@ static void hfp_ag_trigger_reject_call(void){ while (btstack_linked_list_iterator_has_next(&it)){ hfp_connection_t * connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it); if (connection->local_role != HFP_ROLE_AG) continue; - if (connection->call_state != HFP_CALL_RINGING && - connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue; + if ((connection->call_state != HFP_CALL_RINGING) && + (connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING)) continue; hfp_ag_hf_stop_ringing(connection); connection->ag_indicators_status_update_bitmap = store_bit(connection->ag_indicators_status_update_bitmap, callsetup_indicator_index, 1); connection->call_state = HFP_CALL_IDLE; @@ -1056,8 +1056,8 @@ static void hfp_ag_stop_ringing(void){ while (btstack_linked_list_iterator_has_next(&it)){ hfp_connection_t * hfp_connection = (hfp_connection_t *)btstack_linked_list_iterator_next(&it); if (hfp_connection->local_role != HFP_ROLE_AG) continue; - if (hfp_connection->call_state != HFP_CALL_RINGING && - hfp_connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING) continue; + if ((hfp_connection->call_state != HFP_CALL_RINGING) && + (hfp_connection->call_state != HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING)) continue; hfp_ag_hf_stop_ringing(hfp_connection); } } diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index e7cab862d..1bdc510ab 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -546,8 +546,8 @@ static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){ } static int hfp_hf_run_for_audio_connection(hfp_connection_t * hfp_connection){ - if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED || - hfp_connection->state > HFP_W2_DISCONNECT_SCO) return 0; + if ((hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) || + (hfp_connection->state > HFP_W2_DISCONNECT_SCO)) return 0; if (hfp_connection->release_audio_connection){ hfp_connection->state = HFP_W4_SCO_DISCONNECTED; @@ -1378,8 +1378,8 @@ void hfp_hf_end_active_and_accept_other(hci_con_handle_t acl_handle){ return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_1 = 1; hfp_run_for_context(hfp_connection); } @@ -1392,8 +1392,8 @@ void hfp_hf_swap_calls(hci_con_handle_t acl_handle){ return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_2 = 1; hfp_run_for_context(hfp_connection); } @@ -1406,8 +1406,8 @@ void hfp_hf_join_held_call(hci_con_handle_t acl_handle){ return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_3 = 1; hfp_run_for_context(hfp_connection); } @@ -1420,8 +1420,8 @@ void hfp_hf_connect_calls(hci_con_handle_t acl_handle){ return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_4 = 1; hfp_run_for_context(hfp_connection); } @@ -1434,8 +1434,8 @@ void hfp_hf_release_call_with_index(hci_con_handle_t acl_handle, int index){ return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_x = 1; hfp_connection->hf_send_chld_x_index = 10 + index; hfp_run_for_context(hfp_connection); @@ -1449,8 +1449,8 @@ void hfp_hf_private_consultation_with_call(hci_con_handle_t acl_handle, int inde return; } - if (hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS || - hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){ + if ((hfp_callsetup_status == HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS) || + (hfp_call_status == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT)){ hfp_connection->hf_send_chld_x = 1; hfp_connection->hf_send_chld_x_index = 20 + index; hfp_run_for_context(hfp_connection); diff --git a/src/classic/hfp_msbc.c b/src/classic/hfp_msbc.c index dcc455ed3..8ef435bcc 100644 --- a/src/classic/hfp_msbc.c +++ b/src/classic/hfp_msbc.c @@ -72,7 +72,7 @@ void hfp_msbc_init(void){ } int hfp_msbc_can_encode_audio_frame_now(void){ - return (sizeof(msbc_buffer) - msbc_buffer_offset) >= MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE; + return (sizeof(msbc_buffer) - msbc_buffer_offset) >= (MSBC_FRAME_SIZE + MSBC_EXTRA_SIZE); } void hfp_msbc_encode_audio_frame(int16_t * pcm_samples){ diff --git a/src/classic/hsp_hs.c b/src/classic/hsp_hs.c index 8a8a1eb06..3e064a2c1 100644 --- a/src/classic/hsp_hs.c +++ b/src/classic/hsp_hs.c @@ -683,7 +683,7 @@ static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uin } void hsp_hs_send_button_press(void){ - if (hsp_state < HSP_RFCOMM_CONNECTION_ESTABLISHED || hsp_state >= HSP_W4_RFCOMM_DISCONNECTED) return; + if ((hsp_state < HSP_RFCOMM_CONNECTION_ESTABLISHED) || (hsp_state >= HSP_W4_RFCOMM_DISCONNECTED)) return; hs_send_button_press = 1; hsp_run(); } diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c index ad48a24c2..eb36603bf 100644 --- a/src/classic/rfcomm.c +++ b/src/classic/rfcomm.c @@ -1731,7 +1731,7 @@ static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t // - channel over open mutliplexer rfcomm_multiplexer_t * multiplexer = rfcomm_multiplexer_for_l2cap_cid(channel); - if (!multiplexer || multiplexer->state != RFCOMM_MULTIPLEXER_OPEN) return; + if ( (multiplexer == NULL) || (multiplexer->state != RFCOMM_MULTIPLEXER_OPEN)) return; // channel data ? // rfcomm: (0) addr [76543 server channel] [2 direction: initiator uses 1] [1 C/R: CMD by initiator = 1] [0 EA=1] diff --git a/src/classic/sdp_client.c b/src/classic/sdp_client.c index 014e23bf4..c2632e75a 100644 --- a/src/classic/sdp_client.c +++ b/src/classic/sdp_client.c @@ -471,7 +471,7 @@ void sdp_client_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p break; } log_info("SDP Client disconnected."); - uint8_t status = sdp_client_state == QUERY_COMPLETE ? 0 : SDP_QUERY_INCOMPLETE; + uint8_t status = (sdp_client_state == QUERY_COMPLETE) ? 0 : SDP_QUERY_INCOMPLETE; sdp_client_state = INIT; sdp_parser_handle_done(status); break; diff --git a/src/classic/sdp_util.c b/src/classic/sdp_util.c index fbb34aef7..a283d0be4 100644 --- a/src/classic/sdp_util.c +++ b/src/classic/sdp_util.c @@ -329,7 +329,7 @@ static void sdp_attribute_list_traverse_sequence(uint8_t * element, sdp_attribut while (pos < end_pos){ de_type_t idType = de_get_element_type(element + pos); de_size_t idSize = de_get_size_type(element + pos); - if (idType != DE_UINT || idSize != DE_SIZE_16) break; // wrong type + if ( (idType != DE_UINT) || (idSize != DE_SIZE_16) ) break; // wrong type uint16_t attribute_id = big_endian_read_16(element, pos + 1); pos += 3; if (pos >= end_pos) break; // array out of bounds diff --git a/src/l2cap.c b/src/l2cap.c index 0be58a03f..3bcd0483d 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -1847,7 +1847,7 @@ static void l2cap_run(void){ #ifdef ENABLE_CLASSIC static void l2cap_handle_connection_complete(hci_con_handle_t con_handle, l2cap_channel_t * channel){ - if (channel->state == L2CAP_STATE_WAIT_CONNECTION_COMPLETE || channel->state == L2CAP_STATE_WILL_SEND_CREATE_CONNECTION) { + if ((channel->state == L2CAP_STATE_WAIT_CONNECTION_COMPLETE) || (channel->state == L2CAP_STATE_WILL_SEND_CREATE_CONNECTION)) { log_info("connection complete con_handle %04x - for channel %p cid 0x%04x", (int) con_handle, channel, channel->local_cid); // success, start l2cap handshake channel->con_handle = con_handle; @@ -2580,7 +2580,7 @@ static void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, u } #endif // check for unknown options - if ((option_hint == 0) && ((option_type < L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT) || option_type > L2CAP_CONFIG_OPTION_TYPE_EXTENDED_WINDOW_SIZE)){ + if ((option_hint == 0) && ((option_type < L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT) || (option_type > L2CAP_CONFIG_OPTION_TYPE_EXTENDED_WINDOW_SIZE))){ log_info("l2cap cid %u, unknown options", channel->local_cid); channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_INVALID); } @@ -2839,7 +2839,7 @@ static void l2cap_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t * uint16_t cmd_len = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET); // not for a particular channel, and not CONNECTION_REQUEST, ECHO_[REQUEST|RESPONSE], INFORMATION_RESPONSE - if ((code < 1) || code == ECHO_RESPONSE || code > INFORMATION_RESPONSE){ + if ((code < 1) || (code == ECHO_RESPONSE) || (code > INFORMATION_RESPONSE)){ l2cap_register_signaling_response(handle, COMMAND_REJECT, sig_id, 0, L2CAP_REJ_CMD_UNKNOWN); return; } @@ -3519,7 +3519,7 @@ static void l2cap_acl_le_handler(hci_con_handle_t handle, uint8_t *packet, uint1 case L2CAP_CID_SIGNALING_LE: { uint16_t sig_id = packet[COMPLETE_L2CAP_HEADER + 1]; uint16_t len = little_endian_read_16(packet, COMPLETE_L2CAP_HEADER + 2); - if (COMPLETE_L2CAP_HEADER + 4 + len > size) break; + if ((COMPLETE_L2CAP_HEADER + 4 + len) > size) break; int valid = l2cap_le_signaling_handler_dispatch(handle, &packet[COMPLETE_L2CAP_HEADER], sig_id); if (!valid){ l2cap_register_signaling_response(handle, COMMAND_REJECT_LE, sig_id, 0, L2CAP_REJ_CMD_UNKNOWN);