Ran SPLINT (secure programming LINT) and fixed warnings.
This commit is contained in:
+18
-10
@@ -169,7 +169,7 @@ struct Address_Cache_Entry *address_remove_oldest(
|
|||||||
if ((pMatch->
|
if ((pMatch->
|
||||||
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
||||||
BAC_ADDR_STATIC)) ==
|
BAC_ADDR_STATIC)) ==
|
||||||
(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) {
|
((uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) {
|
||||||
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||||
ulTime = pMatch->TimeToLive;
|
ulTime = pMatch->TimeToLive;
|
||||||
pCandidate = pMatch;
|
pCandidate = pMatch;
|
||||||
@@ -239,7 +239,7 @@ void address_file_init(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
address_add((uint32_t) device_id, max_apdu, &src);
|
address_add((uint32_t) device_id, max_apdu, &src);
|
||||||
address_set_device_TTL(device_id, 0, true); /* Mark as static entry */
|
address_set_device_TTL((uint32_t)device_id, 0, true); /* Mark as static entry */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -494,9 +494,11 @@ bool address_bind_request(
|
|||||||
pMatch = Address_Cache;
|
pMatch = Address_Cache;
|
||||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) == 0) {
|
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) == 0) {
|
||||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ; /* In use and awaiting binding */
|
/* In use and awaiting binding */
|
||||||
|
pMatch->Flags = (uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ);
|
||||||
pMatch->device_id = device_id;
|
pMatch->device_id = device_id;
|
||||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
/* No point in leaving bind requests in for long haul */
|
||||||
|
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||||
/* now would be a good time to do a Who-Is request */
|
/* now would be a good time to do a Who-Is request */
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
@@ -506,9 +508,10 @@ bool address_bind_request(
|
|||||||
/* No free entries, See if we can squeeze it in by dropping an existing one */
|
/* No free entries, See if we can squeeze it in by dropping an existing one */
|
||||||
pMatch = address_remove_oldest();
|
pMatch = address_remove_oldest();
|
||||||
if (pMatch != NULL) {
|
if (pMatch != NULL) {
|
||||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ;
|
pMatch->Flags = (uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ);
|
||||||
pMatch->device_id = device_id;
|
pMatch->device_id = device_id;
|
||||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
/* No point in leaving bind requests in for long haul */
|
||||||
|
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||||
}
|
}
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
@@ -528,9 +531,13 @@ void address_add_binding(
|
|||||||
(pMatch->device_id == device_id)) {
|
(pMatch->device_id == device_id)) {
|
||||||
pMatch->address = *src;
|
pMatch->address = *src;
|
||||||
pMatch->max_apdu = max_apdu;
|
pMatch->max_apdu = max_apdu;
|
||||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag in case it was set */
|
/* Clear bind request flag in case it was set */
|
||||||
if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) /* Only update TTL if not static */
|
pMatch->Flags &= ~BAC_ADDR_BIND_REQ;
|
||||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* and set it on a long fuse */
|
/* Only update TTL if not static */
|
||||||
|
if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) {
|
||||||
|
/* and set it on a long fuse */
|
||||||
|
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pMatch++;
|
pMatch++;
|
||||||
@@ -569,7 +576,8 @@ unsigned address_count(
|
|||||||
|
|
||||||
pMatch = Address_Cache;
|
pMatch = Address_Cache;
|
||||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) /* Only count bound entries */
|
/* Only count bound entries */
|
||||||
|
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE)
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
pMatch++;
|
pMatch++;
|
||||||
|
|||||||
@@ -1193,7 +1193,7 @@ int encode_context_unsigned(
|
|||||||
len = 4;
|
len = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = encode_tag(&apdu[0], tag_number, true, len);
|
len = encode_tag(&apdu[0], tag_number, true, (uint32_t)len);
|
||||||
len += encode_bacnet_unsigned(&apdu[len], value);
|
len += encode_bacnet_unsigned(&apdu[len], value);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@@ -1566,7 +1566,7 @@ int decode_bacnet_time_safe(
|
|||||||
btime->hundredths = 0;
|
btime->hundredths = 0;
|
||||||
btime->min = 0;
|
btime->min = 0;
|
||||||
btime->sec = 0;
|
btime->sec = 0;
|
||||||
return len_value;
|
return (int)len_value;
|
||||||
} else {
|
} else {
|
||||||
return decode_bacnet_time(apdu, btime);
|
return decode_bacnet_time(apdu, btime);
|
||||||
}
|
}
|
||||||
@@ -1699,7 +1699,7 @@ int decode_date_safe(
|
|||||||
bdate->month = 0;
|
bdate->month = 0;
|
||||||
bdate->wday = 0;
|
bdate->wday = 0;
|
||||||
bdate->year = 0;
|
bdate->year = 0;
|
||||||
return len_value;
|
return (int)len_value;
|
||||||
} else {
|
} else {
|
||||||
return decode_date(apdu, bdate);
|
return decode_date(apdu, bdate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ int decode_real_safe(
|
|||||||
{
|
{
|
||||||
if (len_value != 4) {
|
if (len_value != 4) {
|
||||||
*real_value = 0.0f;
|
*real_value = 0.0f;
|
||||||
return len_value;
|
return (int)len_value;
|
||||||
} else {
|
} else {
|
||||||
return decode_real(apdu, real_value);
|
return decode_real(apdu, real_value);
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ int decode_double_safe(
|
|||||||
{
|
{
|
||||||
if (len_value != 8) {
|
if (len_value != 8) {
|
||||||
*double_value = 0.0;
|
*double_value = 0.0;
|
||||||
return len_value;
|
return (int)len_value;
|
||||||
} else {
|
} else {
|
||||||
return decode_double(apdu, double_value);
|
return decode_double(apdu, double_value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,12 +198,14 @@ bool bitstring_same(
|
|||||||
BACNET_BIT_STRING * bitstring2)
|
BACNET_BIT_STRING * bitstring2)
|
||||||
{
|
{
|
||||||
int i = 0; /* loop counter */
|
int i = 0; /* loop counter */
|
||||||
|
int bytes_used = 0;
|
||||||
|
uint8_t compare_mask = 0;
|
||||||
|
|
||||||
if (bitstring1 && bitstring1) {
|
if (bitstring1 && bitstring1) {
|
||||||
if ((bitstring1->bits_used == bitstring2->bits_used) &&
|
if ((bitstring1->bits_used == bitstring2->bits_used) &&
|
||||||
(bitstring1->bits_used / 8 <= MAX_BITSTRING_BYTES)) {
|
(bitstring1->bits_used / 8 <= MAX_BITSTRING_BYTES)) {
|
||||||
int bytes_used = bitstring1->bits_used / 8;
|
bytes_used = (int)(bitstring1->bits_used / 8);
|
||||||
uint8_t compare_mask = 0xFF >> (8 - (bitstring1->bits_used % 8));
|
compare_mask = 0xFF >> (8 - (bitstring1->bits_used % 8));
|
||||||
|
|
||||||
for (i = 0; i < bytes_used; i++) {
|
for (i = 0; i < bytes_used; i++) {
|
||||||
if (bitstring1->value[i] != bitstring2->value[i]) {
|
if (bitstring1->value[i] != bitstring2->value[i]) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ int getevent_encode_apdu(
|
|||||||
if (lastReceivedObjectIdentifier) {
|
if (lastReceivedObjectIdentifier) {
|
||||||
len =
|
len =
|
||||||
encode_context_object_id(&apdu[apdu_len], 0,
|
encode_context_object_id(&apdu[apdu_len], 0,
|
||||||
lastReceivedObjectIdentifier->type,
|
(int)lastReceivedObjectIdentifier->type,
|
||||||
lastReceivedObjectIdentifier->instance);
|
lastReceivedObjectIdentifier->instance);
|
||||||
apdu_len += len;
|
apdu_len += len;
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ int getevent_ack_encode_apdu_data(
|
|||||||
/* Tag 0: objectIdentifier */
|
/* Tag 0: objectIdentifier */
|
||||||
apdu_len +=
|
apdu_len +=
|
||||||
encode_context_object_id(&apdu[apdu_len], 0,
|
encode_context_object_id(&apdu[apdu_len], 0,
|
||||||
event_data->objectIdentifier.type,
|
(int)event_data->objectIdentifier.type,
|
||||||
event_data->objectIdentifier.instance);
|
event_data->objectIdentifier.instance);
|
||||||
/* Tag 1: eventState */
|
/* Tag 1: eventState */
|
||||||
apdu_len +=
|
apdu_len +=
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ void MSTP_Receive_Frame_FSM(
|
|||||||
/* NoData */
|
/* NoData */
|
||||||
else if (mstp_port->DataLength == 0) {
|
else if (mstp_port->DataLength == 0) {
|
||||||
printf_receive_data("%s",
|
printf_receive_data("%s",
|
||||||
mstptext_frame_type(mstp_port->FrameType));
|
mstptext_frame_type((unsigned)mstp_port->FrameType));
|
||||||
if ((mstp_port->DestinationAddress ==
|
if ((mstp_port->DestinationAddress ==
|
||||||
mstp_port->This_Station)
|
mstp_port->This_Station)
|
||||||
|| (mstp_port->DestinationAddress ==
|
|| (mstp_port->DestinationAddress ==
|
||||||
@@ -528,7 +528,7 @@ void MSTP_Receive_Frame_FSM(
|
|||||||
mstp_port->DataCRC);
|
mstp_port->DataCRC);
|
||||||
mstp_port->DataCRCActualLSB = mstp_port->DataRegister;
|
mstp_port->DataCRCActualLSB = mstp_port->DataRegister;
|
||||||
printf_receive_data("%s",
|
printf_receive_data("%s",
|
||||||
mstptext_frame_type(mstp_port->FrameType));
|
mstptext_frame_type((unsigned)mstp_port->FrameType));
|
||||||
/* STATE DATA CRC - no need for new state */
|
/* STATE DATA CRC - no need for new state */
|
||||||
/* indicate the complete reception of a valid frame */
|
/* indicate the complete reception of a valid frame */
|
||||||
if (mstp_port->DataCRC == 0xF0B8) {
|
if (mstp_port->DataCRC == 0xF0B8) {
|
||||||
@@ -634,7 +634,7 @@ bool MSTP_Master_Node_FSM(
|
|||||||
mstp_port->SourceAddress, mstp_port->DestinationAddress,
|
mstp_port->SourceAddress, mstp_port->DestinationAddress,
|
||||||
mstp_port->DataLength, mstp_port->FrameCount,
|
mstp_port->DataLength, mstp_port->FrameCount,
|
||||||
mstp_port->SilenceTimer(),
|
mstp_port->SilenceTimer(),
|
||||||
mstptext_frame_type(mstp_port->FrameType));
|
mstptext_frame_type((unsigned)mstp_port->FrameType));
|
||||||
/* destined for me! */
|
/* destined for me! */
|
||||||
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
||||||
|| (mstp_port->DestinationAddress ==
|
|| (mstp_port->DestinationAddress ==
|
||||||
@@ -663,12 +663,12 @@ bool MSTP_Master_Node_FSM(
|
|||||||
break;
|
break;
|
||||||
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
||||||
/* indicate successful reception to the higher layers */
|
/* indicate successful reception to the higher layers */
|
||||||
MSTP_Put_Receive(mstp_port);
|
(void)MSTP_Put_Receive(mstp_port);
|
||||||
break;
|
break;
|
||||||
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
|
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
|
||||||
/*mstp_port->ReplyPostponedTimer = 0; */
|
/*mstp_port->ReplyPostponedTimer = 0; */
|
||||||
/* indicate successful reception to the higher layers */
|
/* indicate successful reception to the higher layers */
|
||||||
MSTP_Put_Receive(mstp_port);
|
(void)MSTP_Put_Receive(mstp_port);
|
||||||
/* broadcast DER just remains IDLE */
|
/* broadcast DER just remains IDLE */
|
||||||
if (mstp_port->DestinationAddress !=
|
if (mstp_port->DestinationAddress !=
|
||||||
MSTP_BROADCAST_ADDRESS) {
|
MSTP_BROADCAST_ADDRESS) {
|
||||||
@@ -701,7 +701,7 @@ bool MSTP_Master_Node_FSM(
|
|||||||
/* more data frames. These may be BACnet Data frames or */
|
/* more data frames. These may be BACnet Data frames or */
|
||||||
/* proprietary frames. */
|
/* proprietary frames. */
|
||||||
/* FIXME: We could wait for up to Tusage_delay */
|
/* FIXME: We could wait for up to Tusage_delay */
|
||||||
length = MSTP_Get_Send(mstp_port, 0);
|
length = (unsigned)MSTP_Get_Send(mstp_port, 0);
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
/* NothingToSend */
|
/* NothingToSend */
|
||||||
mstp_port->FrameCount = mstp_port->Nmax_info_frames;
|
mstp_port->FrameCount = mstp_port->Nmax_info_frames;
|
||||||
@@ -778,7 +778,7 @@ bool MSTP_Master_Node_FSM(
|
|||||||
/* ReceivedReply */
|
/* ReceivedReply */
|
||||||
/* or a proprietary type that indicates a reply */
|
/* or a proprietary type that indicates a reply */
|
||||||
/* indicate successful reception to the higher layers */
|
/* indicate successful reception to the higher layers */
|
||||||
MSTP_Put_Receive(mstp_port);
|
(void)MSTP_Put_Receive(mstp_port);
|
||||||
mstp_port->master_state =
|
mstp_port->master_state =
|
||||||
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
|
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
|
||||||
break;
|
break;
|
||||||
@@ -1036,7 +1036,7 @@ bool MSTP_Master_Node_FSM(
|
|||||||
/* BACnet Data Expecting Reply, a Test_Request, or */
|
/* BACnet Data Expecting Reply, a Test_Request, or */
|
||||||
/* a proprietary frame that expects a reply is received. */
|
/* a proprietary frame that expects a reply is received. */
|
||||||
/* FIXME: we could wait for up to Treply_delay */
|
/* FIXME: we could wait for up to Treply_delay */
|
||||||
length = MSTP_Get_Reply(mstp_port, 0);
|
length = (unsigned)MSTP_Get_Reply(mstp_port, 0);
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
/* Reply */
|
/* Reply */
|
||||||
/* If a reply is available from the higher layers */
|
/* If a reply is available from the higher layers */
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ int ptransfer_encode_apdu(
|
|||||||
apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER;
|
apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER;
|
||||||
apdu_len = 4;
|
apdu_len = 4;
|
||||||
apdu_len =
|
apdu_len =
|
||||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), private_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return apdu_len;
|
return apdu_len;
|
||||||
@@ -105,7 +105,7 @@ int uptransfer_encode_apdu(
|
|||||||
apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER;
|
apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER;
|
||||||
apdu_len = 2;
|
apdu_len = 2;
|
||||||
apdu_len =
|
apdu_len =
|
||||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), private_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return apdu_len;
|
return apdu_len;
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ int rr_decode_service_request(
|
|||||||
rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */
|
rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */
|
||||||
if (len < apdu_len) {
|
if (len < apdu_len) {
|
||||||
TagLen =
|
TagLen =
|
||||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
(unsigned)decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||||
&len_value_type);
|
&len_value_type);
|
||||||
if (tag_number == 2) {
|
if (tag_number == 2) {
|
||||||
len += TagLen;
|
len += TagLen;
|
||||||
|
|||||||
Reference in New Issue
Block a user