Fixed some warnings flagged by IAR C-STAT static analysis tool.

This commit is contained in:
skarg
2016-01-07 21:31:38 +00:00
parent dd0fb9c841
commit 0697065030
16 changed files with 51 additions and 52 deletions
+2 -2
View File
@@ -193,13 +193,13 @@ void handler_device_communication_control(
len = len =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
#if PRINT_ENABLED
fprintf(stderr, fprintf(stderr,
"DeviceCommunicationControl: " "Failed to send PDU (%s)!\n", "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n",
strerror(errno)); strerror(errno));
}
#endif #endif
}
return; return;
} }
+2 -2
View File
@@ -162,12 +162,12 @@ void handler_reinitialize_device(
len = len =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (len <= 0) { if (len <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
strerror(errno)); strerror(errno));
}
#endif #endif
}
return; return;
} }
+2 -4
View File
@@ -193,13 +193,11 @@ void handler_read_property(
bytes_sent = bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
}
return; return;
} }
+2 -4
View File
@@ -453,11 +453,9 @@ void handler_read_property_multiple(
bytes_sent = bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "RPM: Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "RPM: Failed to send PDU (%s)!\n", strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
}
} }
+2 -4
View File
@@ -136,13 +136,11 @@ void handler_write_property(
bytes_sent = bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno)); fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
}
return; return;
} }
+6 -6
View File
@@ -79,13 +79,13 @@ void handler_unrecognized_service(
bytes_sent = bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (bytes_sent > 0) { if (bytes_sent > 0) {
#if PRINT_ENABLED
fprintf(stderr, "Sent Reject!\n"); fprintf(stderr, "Sent Reject!\n");
} else {
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
} else {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno));
#endif
}
} }
+3 -5
View File
@@ -103,13 +103,11 @@ void Send_I_Am(
/* send data */ /* send data */
bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
}
} }
/** Encode an I Am message to be unicast directly back to the src. /** 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) if (bytes_sent <= 0)
fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno));
#else #else
bytes_sent = bytes_sent; (void)bytes_sent;
#endif #endif
} }
+2 -4
View File
@@ -91,12 +91,10 @@ void Send_I_Have(
bytes_sent = bytes_sent =
datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0],
pdu_len); pdu_len);
#if PRINT_ENABLED
if (bytes_sent <= 0) { if (bytes_sent <= 0) {
#if PRINT_ENABLED
fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n",
strerror(errno)); strerror(errno));
}
#else
bytes_sent = bytes_sent;
#endif #endif
}
} }
+1 -1
View File
@@ -215,7 +215,7 @@ uint8_t automac_free_address_random(
count = automac_free_address_count(); count = automac_free_address_count();
if (count) { if (count) {
random_count = rand() % count; random_count =(uint8_t)(rand() % count);
mac = automac_free_address_mac(random_count); mac = automac_free_address_mac(random_count);
} }
+2 -2
View File
@@ -339,7 +339,7 @@ unsigned Device_Count(
uint32_t Device_Index_To_Instance( uint32_t Device_Index_To_Instance(
unsigned index) unsigned index)
{ {
index = index; (void)index;
return Object_Instance_Number; return Object_Instance_Number;
} }
@@ -957,7 +957,7 @@ bool Device_Write_Property_Local(
break; break;
} }
/* not using len at this time */ /* not using len at this time */
len = len; (void)len;
return status; return status;
} }
+4 -4
View File
@@ -212,7 +212,7 @@ void dlmstp_automac_hander(
bool dlmstp_init( bool dlmstp_init(
char *ifname) char *ifname)
{ {
ifname = ifname; (void)ifname;
Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer, Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer,
sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT); sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT);
Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer, 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); crc8 = CRC_Calc_Header(pkt->buffer[5], crc8);
pkt->buffer[6] = data_len % 256; pkt->buffer[6] = data_len % 256;
crc8 = CRC_Calc_Header(pkt->buffer[6], crc8); crc8 = CRC_Calc_Header(pkt->buffer[6], crc8);
pkt->buffer[7] = ~crc8; pkt->buffer[7] = (uint8_t)(~crc8);
pkt->length = 8; pkt->length = 8;
if (data_len) { if (data_len) {
/* calculate CRC for any data */ /* calculate CRC for any data */
@@ -1214,7 +1214,7 @@ static bool MSTP_Master_Node_FSM(
/* a proprietary frame that expects a reply is received. */ /* a proprietary frame that expects a reply is received. */
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST: case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue); pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue);
if (pkt != NULL) { if (pkt) {
matched = matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0], dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &pkt->buffer[0], pkt->length, DataLength, SourceAddress, &pkt->buffer[0], pkt->length,
@@ -1243,7 +1243,7 @@ static bool MSTP_Master_Node_FSM(
MSTP_Flag.ReceivedValidFrame = false; MSTP_Flag.ReceivedValidFrame = false;
/* clear the queue */ /* clear the queue */
(void) Ringbuf_Pop(&PDU_Queue, NULL); (void) Ringbuf_Pop(&PDU_Queue, NULL);
} else if (rs485_silence_elapsed(Treply_delay) || (pkt != NULL)) { } else if (rs485_silence_elapsed(Treply_delay) || pkt) {
/* DeferredReply */ /* DeferredReply */
/* If no reply will be available from the higher layers */ /* If no reply will be available from the higher layers */
/* within Treply_delay after the reception of the */ /* within Treply_delay after the reception of the */
+5 -1
View File
@@ -86,7 +86,11 @@ static uint16_t rs485_turnaround_time(
/* delay after reception before transmitting - per MS/TP spec */ /* delay after reception before transmitting - per MS/TP spec */
/* wait a minimum 40 bit times since reception */ /* wait a minimum 40 bit times since reception */
/* at least 2 ms for errors: rounding, clock tick */ /* 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;
}
} }
/************************************************************************* /*************************************************************************
+1 -2
View File
@@ -462,8 +462,7 @@ void apdu_handler(
/* PDU Type */ /* PDU Type */
switch (apdu[0] & 0xF0) { switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0],
(int) apdu_decode_confirmed_service_request(&apdu[0],
apdu_len, &service_data, &service_choice, &service_request, apdu_len, &service_data, &service_choice, &service_request,
&service_request_len); &service_request_len);
if (apdu_confirmed_dcc_disabled(service_choice)) { if (apdu_confirmed_dcc_disabled(service_choice)) {
+6 -4
View File
@@ -292,7 +292,9 @@ int bacapp_decode_data(
(tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) && (tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) &&
(tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING)) { (tag_data_type != BACNET_APPLICATION_TAG_OCTET_STRING)) {
/* indicate that we were not able to decode the value */ /* 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; return len;
} }
@@ -309,7 +311,7 @@ int bacapp_decode_application_data(
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
/* FIXME: use max_apdu_len! */ /* FIXME: use max_apdu_len! */
max_apdu_len = max_apdu_len; (void)max_apdu_len;
if (apdu && value && !IS_CONTEXT_SPECIFIC(*apdu)) { if (apdu && value && !IS_CONTEXT_SPECIFIC(*apdu)) {
value->context_specific = false; value->context_specific = false;
tag_len = tag_len =
@@ -446,7 +448,7 @@ int bacapp_decode_application_data_len(
uint32_t len_value_type = 0; uint32_t len_value_type = 0;
/* FIXME: use max_apdu_len! */ /* FIXME: use max_apdu_len! */
max_apdu_len = max_apdu_len; (void)max_apdu_len;
if (apdu && !IS_CONTEXT_SPECIFIC(*apdu)) { if (apdu && !IS_CONTEXT_SPECIFIC(*apdu)) {
tag_len = tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number, decode_tag_number_and_value(&apdu[0], &tag_number,
@@ -798,7 +800,7 @@ int bacapp_decode_context_data_len(
uint8_t tag = 0; uint8_t tag = 0;
/* FIXME: use max_apdu_len! */ /* FIXME: use max_apdu_len! */
max_apdu_len = max_apdu_len; (void)max_apdu_len;
if (apdu && IS_CONTEXT_SPECIFIC(*apdu)) { if (apdu && IS_CONTEXT_SPECIFIC(*apdu)) {
tag_len = tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number, decode_tag_number_and_value(&apdu[0], &tag_number,
+4 -2
View File
@@ -883,8 +883,10 @@ int encode_octet_string(
to bounds check since it might not be the only data chunk */ to bounds check since it might not be the only data chunk */
len = (int) octetstring_length(octet_string); len = (int) octetstring_length(octet_string);
value = octetstring_value(octet_string); value = octetstring_value(octet_string);
for (i = 0; i < len; i++) { if (value) {
apdu[i] = value[i]; for (i = 0; i < len; i++) {
apdu[i] = value[i];
}
} }
} }
+4 -2
View File
@@ -98,7 +98,7 @@ int rp_decode_service_request(
uint32_t array_value = 0; /* for decoding */ uint32_t array_value = 0; /* for decoding */
/* check for value pointers */ /* check for value pointers */
if (rpdata != NULL) { if (rpdata) {
/* Must have at least 2 tags, an object id and a property identifier /* 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 */ * of at least 1 byte in length to have any chance of parsing */
if (apdu_len < 7) { if (apdu_len < 7) {
@@ -142,7 +142,9 @@ int rp_decode_service_request(
if (len < apdu_len) { if (len < apdu_len) {
/* If something left over now, we have an invalid request */ /* 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; return BACNET_STATUS_REJECT;
} }