From 0697065030760dcdc4530e47b5b8a113d9a038cd Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 7 Jan 2016 21:31:38 +0000 Subject: [PATCH] Fixed some warnings flagged by IAR C-STAT static analysis tool. --- bacnet-stack/demo/handler/h_dcc.c | 4 ++-- bacnet-stack/demo/handler/h_rd.c | 4 ++-- bacnet-stack/demo/handler/h_rp.c | 6 ++---- bacnet-stack/demo/handler/h_rpm.c | 6 ++---- bacnet-stack/demo/handler/h_wp.c | 6 ++---- bacnet-stack/demo/handler/noserv.c | 12 ++++++------ bacnet-stack/demo/handler/s_iam.c | 8 +++----- bacnet-stack/demo/handler/s_ihave.c | 6 ++---- bacnet-stack/ports/stm32f10x/automac.c | 2 +- bacnet-stack/ports/stm32f10x/device.c | 4 ++-- bacnet-stack/ports/stm32f10x/dlmstp.c | 8 ++++---- bacnet-stack/ports/stm32f10x/rs485.c | 6 +++++- bacnet-stack/src/apdu.c | 9 ++++----- bacnet-stack/src/bacapp.c | 10 ++++++---- bacnet-stack/src/bacdcode.c | 6 ++++-- bacnet-stack/src/rp.c | 6 ++++-- 16 files changed, 51 insertions(+), 52 deletions(-) diff --git a/bacnet-stack/demo/handler/h_dcc.c b/bacnet-stack/demo/handler/h_dcc.c index 3d4441bf..552748a4 100644 --- a/bacnet-stack/demo/handler/h_dcc.c +++ b/bacnet-stack/demo/handler/h_dcc.c @@ -193,13 +193,13 @@ void handler_device_communication_control( len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (len <= 0) { +#if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n", strerror(errno)); - } #endif + } return; } diff --git a/bacnet-stack/demo/handler/h_rd.c b/bacnet-stack/demo/handler/h_rd.c index 287d19ec..a9a44154 100644 --- a/bacnet-stack/demo/handler/h_rd.c +++ b/bacnet-stack/demo/handler/h_rd.c @@ -162,12 +162,12 @@ void handler_reinitialize_device( len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (len <= 0) { +#if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", strerror(errno)); - } #endif + } return; } diff --git a/bacnet-stack/demo/handler/h_rp.c b/bacnet-stack/demo/handler/h_rp.c index bdaed213..d1d27316 100644 --- a/bacnet-stack/demo/handler/h_rp.c +++ b/bacnet-stack/demo/handler/h_rp.c @@ -193,13 +193,11 @@ void handler_read_property( bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { +#if PRINT_ENABLED fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } return; } diff --git a/bacnet-stack/demo/handler/h_rpm.c b/bacnet-stack/demo/handler/h_rpm.c index 38c6d0ee..48f24fe9 100644 --- a/bacnet-stack/demo/handler/h_rpm.c +++ b/bacnet-stack/demo/handler/h_rpm.c @@ -453,11 +453,9 @@ void handler_read_property_multiple( bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { +#if PRINT_ENABLED fprintf(stderr, "RPM: Failed to send PDU (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } } diff --git a/bacnet-stack/demo/handler/h_wp.c b/bacnet-stack/demo/handler/h_wp.c index 9dcd21f3..36f7b43f 100644 --- a/bacnet-stack/demo/handler/h_wp.c +++ b/bacnet-stack/demo/handler/h_wp.c @@ -136,13 +136,11 @@ void handler_write_property( bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { +#if PRINT_ENABLED fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } return; } diff --git a/bacnet-stack/demo/handler/noserv.c b/bacnet-stack/demo/handler/noserv.c index 0781e98a..5a8faa66 100644 --- a/bacnet-stack/demo/handler/noserv.c +++ b/bacnet-stack/demo/handler/noserv.c @@ -79,13 +79,13 @@ void handler_unrecognized_service( bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent > 0) { +#if PRINT_ENABLED fprintf(stderr, "Sent Reject!\n"); - } else { - fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } else { +#if PRINT_ENABLED + fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); +#endif + } } diff --git a/bacnet-stack/demo/handler/s_iam.c b/bacnet-stack/demo/handler/s_iam.c index 39905cc1..35a70755 100644 --- a/bacnet-stack/demo/handler/s_iam.c +++ b/bacnet-stack/demo/handler/s_iam.c @@ -103,13 +103,11 @@ void Send_I_Am( /* send data */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { +#if PRINT_ENABLED fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } } /** Encode an I Am message to be unicast directly back to the src. @@ -189,6 +187,6 @@ void Send_I_Am_Unicast( if (bytes_sent <= 0) fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); #else - bytes_sent = bytes_sent; + (void)bytes_sent; #endif } diff --git a/bacnet-stack/demo/handler/s_ihave.c b/bacnet-stack/demo/handler/s_ihave.c index d0dd256d..cbd16ba1 100644 --- a/bacnet-stack/demo/handler/s_ihave.c +++ b/bacnet-stack/demo/handler/s_ihave.c @@ -91,12 +91,10 @@ void Send_I_Have( bytes_sent = datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { +#if PRINT_ENABLED fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno)); - } -#else - bytes_sent = bytes_sent; #endif + } } diff --git a/bacnet-stack/ports/stm32f10x/automac.c b/bacnet-stack/ports/stm32f10x/automac.c index 28c6d209..adb28ac7 100644 --- a/bacnet-stack/ports/stm32f10x/automac.c +++ b/bacnet-stack/ports/stm32f10x/automac.c @@ -215,7 +215,7 @@ uint8_t automac_free_address_random( count = automac_free_address_count(); if (count) { - random_count = rand() % count; + random_count =(uint8_t)(rand() % count); mac = automac_free_address_mac(random_count); } diff --git a/bacnet-stack/ports/stm32f10x/device.c b/bacnet-stack/ports/stm32f10x/device.c index 7dc18577..6110f90b 100644 --- a/bacnet-stack/ports/stm32f10x/device.c +++ b/bacnet-stack/ports/stm32f10x/device.c @@ -339,7 +339,7 @@ unsigned Device_Count( uint32_t Device_Index_To_Instance( unsigned index) { - index = index; + (void)index; return Object_Instance_Number; } @@ -957,7 +957,7 @@ bool Device_Write_Property_Local( break; } /* not using len at this time */ - len = len; + (void)len; return status; } diff --git a/bacnet-stack/ports/stm32f10x/dlmstp.c b/bacnet-stack/ports/stm32f10x/dlmstp.c index 002cddc8..6c5693b4 100644 --- a/bacnet-stack/ports/stm32f10x/dlmstp.c +++ b/bacnet-stack/ports/stm32f10x/dlmstp.c @@ -212,7 +212,7 @@ void dlmstp_automac_hander( bool dlmstp_init( char *ifname) { - ifname = ifname; + (void)ifname; Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer, sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT); Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer, @@ -466,7 +466,7 @@ static void MSTP_Send_Frame( crc8 = CRC_Calc_Header(pkt->buffer[5], crc8); pkt->buffer[6] = data_len % 256; crc8 = CRC_Calc_Header(pkt->buffer[6], crc8); - pkt->buffer[7] = ~crc8; + pkt->buffer[7] = (uint8_t)(~crc8); pkt->length = 8; if (data_len) { /* calculate CRC for any data */ @@ -1214,7 +1214,7 @@ static bool MSTP_Master_Node_FSM( /* a proprietary frame that expects a reply is received. */ case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST: pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue); - if (pkt != NULL) { + if (pkt) { matched = dlmstp_compare_data_expecting_reply(&InputBuffer[0], DataLength, SourceAddress, &pkt->buffer[0], pkt->length, @@ -1243,7 +1243,7 @@ static bool MSTP_Master_Node_FSM( MSTP_Flag.ReceivedValidFrame = false; /* clear the queue */ (void) Ringbuf_Pop(&PDU_Queue, NULL); - } else if (rs485_silence_elapsed(Treply_delay) || (pkt != NULL)) { + } else if (rs485_silence_elapsed(Treply_delay) || pkt) { /* DeferredReply */ /* If no reply will be available from the higher layers */ /* within Treply_delay after the reception of the */ diff --git a/bacnet-stack/ports/stm32f10x/rs485.c b/bacnet-stack/ports/stm32f10x/rs485.c index b0af6a7f..0475586f 100644 --- a/bacnet-stack/ports/stm32f10x/rs485.c +++ b/bacnet-stack/ports/stm32f10x/rs485.c @@ -86,7 +86,11 @@ static uint16_t rs485_turnaround_time( /* delay after reception before transmitting - per MS/TP spec */ /* wait a minimum 40 bit times since reception */ /* at least 2 ms for errors: rounding, clock tick */ - return (2 + ((Tturnaround * 1000UL) / Baud_Rate)); + if (Baud_Rate) { + return (2 + ((Tturnaround * 1000UL) / Baud_Rate)); + } else { + return 2; + } } /************************************************************************* diff --git a/bacnet-stack/src/apdu.c b/bacnet-stack/src/apdu.c index 6ac2e6ad..1305671a 100644 --- a/bacnet-stack/src/apdu.c +++ b/bacnet-stack/src/apdu.c @@ -378,8 +378,8 @@ void apdu_retries_set( /* When network communications are completely disabled, only DeviceCommunicationControl and ReinitializeDevice APDUs shall be processed and no messages shall be initiated. - When the initiation of communications is disabled, - all APDUs shall be processed and responses returned as + When the initiation of communications is disabled, + all APDUs shall be processed and responses returned as required... */ static bool apdu_confirmed_dcc_disabled( uint8_t service_choice) @@ -413,7 +413,7 @@ static bool apdu_unconfirmed_dcc_disabled( bool status = false; if (dcc_communication_disabled()) { - /* there are no Unconfirmed messages that + /* there are no Unconfirmed messages that can be processed in this state */ status = true; } else if (dcc_communication_initiation_disabled()) { @@ -462,8 +462,7 @@ void apdu_handler( /* PDU Type */ switch (apdu[0] & 0xF0) { case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: - len = - (int) apdu_decode_confirmed_service_request(&apdu[0], + apdu_decode_confirmed_service_request(&apdu[0], apdu_len, &service_data, &service_choice, &service_request, &service_request_len); if (apdu_confirmed_dcc_disabled(service_choice)) { diff --git a/bacnet-stack/src/bacapp.c b/bacnet-stack/src/bacapp.c index c6e17b7f..e6175231 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -292,7 +292,9 @@ int bacapp_decode_data( (tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) && (tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING)) { /* indicate that we were not able to decode the value */ - value->tag = MAX_BACNET_APPLICATION_TAG; + if (value) { + value->tag = MAX_BACNET_APPLICATION_TAG; + } } return len; } @@ -309,7 +311,7 @@ int bacapp_decode_application_data( uint32_t len_value_type = 0; /* FIXME: use max_apdu_len! */ - max_apdu_len = max_apdu_len; + (void)max_apdu_len; if (apdu && value && !IS_CONTEXT_SPECIFIC(*apdu)) { value->context_specific = false; tag_len = @@ -446,7 +448,7 @@ int bacapp_decode_application_data_len( uint32_t len_value_type = 0; /* FIXME: use max_apdu_len! */ - max_apdu_len = max_apdu_len; + (void)max_apdu_len; if (apdu && !IS_CONTEXT_SPECIFIC(*apdu)) { tag_len = decode_tag_number_and_value(&apdu[0], &tag_number, @@ -798,7 +800,7 @@ int bacapp_decode_context_data_len( uint8_t tag = 0; /* FIXME: use max_apdu_len! */ - max_apdu_len = max_apdu_len; + (void)max_apdu_len; if (apdu && IS_CONTEXT_SPECIFIC(*apdu)) { tag_len = decode_tag_number_and_value(&apdu[0], &tag_number, diff --git a/bacnet-stack/src/bacdcode.c b/bacnet-stack/src/bacdcode.c index ef1ce8e2..dd0457f8 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -883,8 +883,10 @@ int encode_octet_string( to bounds check since it might not be the only data chunk */ len = (int) octetstring_length(octet_string); value = octetstring_value(octet_string); - for (i = 0; i < len; i++) { - apdu[i] = value[i]; + if (value) { + for (i = 0; i < len; i++) { + apdu[i] = value[i]; + } } } diff --git a/bacnet-stack/src/rp.c b/bacnet-stack/src/rp.c index cd9bf893..c711cae2 100644 --- a/bacnet-stack/src/rp.c +++ b/bacnet-stack/src/rp.c @@ -98,7 +98,7 @@ int rp_decode_service_request( uint32_t array_value = 0; /* for decoding */ /* check for value pointers */ - if (rpdata != NULL) { + if (rpdata) { /* Must have at least 2 tags, an object id and a property identifier * of at least 1 byte in length to have any chance of parsing */ if (apdu_len < 7) { @@ -142,7 +142,9 @@ int rp_decode_service_request( if (len < apdu_len) { /* If something left over now, we have an invalid request */ - rpdata->error_code = ERROR_CODE_REJECT_TOO_MANY_ARGUMENTS; + if (rpdata) { + rpdata->error_code = ERROR_CODE_REJECT_TOO_MANY_ARGUMENTS; + } return BACNET_STATUS_REJECT; }