From e77e070d90dd9e5b1ca30dbb61acdd8d495aa783 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Mon, 6 Apr 2026 11:51:36 -0500 Subject: [PATCH] Fix type definitions for inner_tag and object_instance when uint32_t is defined as long unsigned int instead of unsigned int (#1293) * Fix type definitions in bacapp.c for inner_tag and object_instance when uint32_t is defined as long unsigned int instead of unsigned int * Change DNET_list type from int to int32_t across multiple files to avoid compiler warnings when int32_t is defined as long int instead of int. --- CHANGELOG.md | 4 ++++ apps/gateway/main.c | 2 +- apps/gateway2/main.c | 2 +- src/bacnet/bacapp.c | 12 ++++++------ src/bacnet/basic/npdu/h_routed_npdu.c | 8 ++++---- src/bacnet/basic/npdu/h_routed_npdu.h | 2 +- src/bacnet/basic/npdu/s_router.c | 21 +++++++++++---------- src/bacnet/basic/npdu/s_router.h | 15 ++++++++------- src/bacnet/basic/service/h_whohas.c | 2 +- src/bacnet/basic/service/h_whois.c | 2 +- 10 files changed, 38 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac4b8f1..b06f17fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -216,6 +216,10 @@ The git repositories are hosted at the following sites: ### Fixed +* Fixed type definition compiler warnings in DNET list when int32_t is + defined as long int instead of int on 32-bit platforms, and in bacapp + module for inner_tag and object_instance when uint32_t is defined + as long unsigned int instead of unsigned int on 32-bit platforms. (#1293) * Fixed CMakeLists.txt by replacing BIG_ENDIAN definition with BACNET_BIG_ENDIAN to fix missing function in builds. (#1284) * Fixed CMakeLists.txt by adding INTRINSIC_REPORTING CMake option diff --git a/apps/gateway/main.c b/apps/gateway/main.c index 4544c5bc..95b43157 100644 --- a/apps/gateway/main.c +++ b/apps/gateway/main.c @@ -53,7 +53,7 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; /** The list of DNETs that our router can reach. * Only one entry since we don't support downstream routers. */ -int DNET_list[2] = { +int32_t DNET_list[2] = { VIRTUAL_DNET, -1 /* Need -1 terminator */ }; diff --git a/apps/gateway2/main.c b/apps/gateway2/main.c index 98f7bb5f..ff60eb63 100644 --- a/apps/gateway2/main.c +++ b/apps/gateway2/main.c @@ -56,7 +56,7 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; /** The list of DNETs that our router can reach. * Only one entry since we don't support downstream routers. */ -int DNET_list[2] = { +int32_t DNET_list[2] = { VIRTUAL_DNET, -1 /* Need -1 terminator */ }; diff --git a/src/bacnet/bacapp.c b/src/bacnet/bacapp.c index 124d4a26..7467d747 100644 --- a/src/bacnet/bacapp.c +++ b/src/bacnet/bacapp.c @@ -4147,7 +4147,7 @@ parse_weeklyschedule(char *str, BACNET_APPLICATION_DATA_VALUE *value) { char *chunk, *comma, *space, *t, *v, *colonpos, *sqpos; int daynum = 0, tvnum = 0; - unsigned int inner_tag; + uint32_t inner_tag; BACNET_APPLICATION_DATA_VALUE dummy_value = { 0 }; BACNET_DAILY_SCHEDULE *dsch; @@ -4179,7 +4179,7 @@ parse_weeklyschedule(char *str, BACNET_APPLICATION_DATA_VALUE *value) return false; } } else { - inner_tag = (int)dummy_value.type.Unsigned_Int; + inner_tag = (uint32_t)dummy_value.type.Unsigned_Int; } chunk = strtok(NULL, ";"); @@ -4810,8 +4810,8 @@ bool bacapp_parse_application_data( #if defined(BACAPP_DATE) int year, month, day, wday; #endif - int object_type = 0; - uint32_t instance = 0; + unsigned int object_type = 0; + unsigned int object_instance = 0; bool status = false; long long_value = 0; BACNET_UNSIGNED_INTEGER unsigned_long_value = 0; @@ -4957,10 +4957,10 @@ bool bacapp_parse_application_data( #endif #if defined(BACAPP_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: - count = sscanf(argv, "%4d:%7u", &object_type, &instance); + count = sscanf(argv, "%4u:%7u", &object_type, &object_instance); if (count == 2) { value->type.Object_Id.type = (uint16_t)object_type; - value->type.Object_Id.instance = instance; + value->type.Object_Id.instance = (uint32_t)object_instance; } else { status = false; } diff --git a/src/bacnet/basic/npdu/h_routed_npdu.c b/src/bacnet/basic/npdu/h_routed_npdu.c index a03e809b..75bd38e8 100644 --- a/src/bacnet/basic/npdu/h_routed_npdu.c +++ b/src/bacnet/basic/npdu/h_routed_npdu.c @@ -50,7 +50,7 @@ */ static void network_control_handler( BACNET_ADDRESS *src, - int *DNET_list, + int32_t *DNET_list, BACNET_NPDU_DATA *npdu_data, uint8_t *npdu, uint16_t npdu_len) @@ -58,6 +58,7 @@ static void network_control_handler( uint16_t npdu_offset = 0; uint16_t dnet = 0; uint16_t len = 0; + int32_t listTerminator = -1; switch (npdu_data->network_message_type) { case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: @@ -133,7 +134,6 @@ static void network_control_handler( * with no routing list of our own. But we don't DO * anything with the info, either. */ - int listTerminator = -1; Send_Initialize_Routing_Table_Ack(src, &listTerminator); } break; @@ -181,7 +181,7 @@ static void network_control_handler( static void routed_apdu_handler( BACNET_ADDRESS *src, BACNET_ADDRESS *dest, - int *DNET_list, + int32_t *DNET_list, uint8_t *apdu, uint16_t apdu_len) { @@ -260,7 +260,7 @@ static void routed_apdu_handler( * @param pdu_len [in] The size of the received message in the pdu[] buffer. */ void routing_npdu_handler( - BACNET_ADDRESS *src, int *DNET_list, uint8_t *pdu, uint16_t pdu_len) + BACNET_ADDRESS *src, int32_t *DNET_list, uint8_t *pdu, uint16_t pdu_len) { int apdu_offset = 0; BACNET_ADDRESS dest = { 0 }; diff --git a/src/bacnet/basic/npdu/h_routed_npdu.h b/src/bacnet/basic/npdu/h_routed_npdu.h index 43ea9830..f349dd6b 100644 --- a/src/bacnet/basic/npdu/h_routed_npdu.h +++ b/src/bacnet/basic/npdu/h_routed_npdu.h @@ -22,7 +22,7 @@ extern "C" { BACNET_STACK_EXPORT void routing_npdu_handler( - BACNET_ADDRESS *src, int *DNET_list, uint8_t *pdu, uint16_t pdu_len); + BACNET_ADDRESS *src, int32_t *DNET_list, uint8_t *pdu, uint16_t pdu_len); #ifdef __cplusplus } diff --git a/src/bacnet/basic/npdu/s_router.c b/src/bacnet/basic/npdu/s_router.c index 705fa839..89ceb0de 100644 --- a/src/bacnet/basic/npdu/s_router.c +++ b/src/bacnet/basic/npdu/s_router.c @@ -46,12 +46,12 @@ int Send_Network_Layer_Message( BACNET_NETWORK_MESSAGE_TYPE network_message_type, BACNET_ADDRESS *dst, - const int *iArgs) + const int32_t *iArgs) { int len = 0; int pdu_len = 0; int bytes_sent = 0; - const int *pVal = iArgs; /* Start with first value */ + const int32_t *pVal = iArgs; /* Start with first value */ bool data_expecting_reply = false; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS bcastDest; @@ -189,7 +189,7 @@ int Send_Network_Layer_Message( * will be sent and the receiving router(s) will send * their full list of reachable BACnet networks. */ -void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet) +void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int32_t dnet) { Send_Network_Layer_Message( NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, dst, &dnet); @@ -204,7 +204,7 @@ void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet) * @param DNET_list [in] List of BACnet network numbers for which I am a router, * terminated with -1 */ -void Send_I_Am_Router_To_Network(const int DNET_list[]) +void Send_I_Am_Router_To_Network(const int32_t DNET_list[]) { /* Use a NULL dst here since we want a broadcast MAC address. */ Send_Network_Layer_Message( @@ -222,9 +222,9 @@ void Send_I_Am_Router_To_Network(const int DNET_list[]) * @param dnet [in] Which BACnet network originated the message. */ void Send_Reject_Message_To_Network( - BACNET_ADDRESS *dst, uint8_t reject_reason, int dnet) + BACNET_ADDRESS *dst, uint8_t reject_reason, int32_t dnet) { - int iArgs[2]; + int32_t iArgs[2]; iArgs[0] = reject_reason; iArgs[1] = dnet; Send_Network_Layer_Message( @@ -248,7 +248,8 @@ void Send_Reject_Message_To_Network( * terminated with -1. Will be just -1 when we are * requesting a routing table. */ -void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[]) +void Send_Initialize_Routing_Table( + BACNET_ADDRESS *dst, const int32_t DNET_list[]) { /* Use a NULL dst here since we want a broadcast MAC address. */ Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst, DNET_list); @@ -272,7 +273,7 @@ void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[]) * should be sent. */ void Send_Initialize_Routing_Table_Ack( - BACNET_ADDRESS *dst, const int DNET_list[]) + BACNET_ADDRESS *dst, const int32_t DNET_list[]) { Send_Network_Layer_Message( NETWORK_MESSAGE_INIT_RT_TABLE_ACK, dst, DNET_list); @@ -288,9 +289,9 @@ void Send_Initialize_Routing_Table_Ack( * will be sent and the receiving router(s) will send * their full list of reachable BACnet networks. */ -void Send_Network_Number_Is(BACNET_ADDRESS *dst, int dnet, int status) +void Send_Network_Number_Is(BACNET_ADDRESS *dst, int32_t dnet, int status) { - int iArgs[2]; + int32_t iArgs[2]; iArgs[0] = dnet; iArgs[1] = status; diff --git a/src/bacnet/basic/npdu/s_router.h b/src/bacnet/basic/npdu/s_router.h index 2a114bec..83f75ad6 100644 --- a/src/bacnet/basic/npdu/s_router.h +++ b/src/bacnet/basic/npdu/s_router.h @@ -25,21 +25,22 @@ BACNET_STACK_EXPORT int Send_Network_Layer_Message( BACNET_NETWORK_MESSAGE_TYPE network_message_type, BACNET_ADDRESS *dst, - const int *iArgs); + const int32_t *iArgs); BACNET_STACK_EXPORT -void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet); +void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int32_t dnet); BACNET_STACK_EXPORT -void Send_I_Am_Router_To_Network(const int DNET_list[]); +void Send_I_Am_Router_To_Network(const int32_t DNET_list[]); BACNET_STACK_EXPORT void Send_Reject_Message_To_Network( - BACNET_ADDRESS *dst, uint8_t reject_reason, int dnet); + BACNET_ADDRESS *dst, uint8_t reject_reason, int32_t dnet); BACNET_STACK_EXPORT -void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[]); +void Send_Initialize_Routing_Table( + BACNET_ADDRESS *dst, const int32_t DNET_list[]); BACNET_STACK_EXPORT void Send_Initialize_Routing_Table_Ack( - BACNET_ADDRESS *dst, const int DNET_list[]); + BACNET_ADDRESS *dst, const int32_t DNET_list[]); BACNET_STACK_EXPORT -void Send_Network_Number_Is(BACNET_ADDRESS *dst, int dnet, int status); +void Send_Network_Number_Is(BACNET_ADDRESS *dst, int32_t dnet, int status); #ifdef __cplusplus } diff --git a/src/bacnet/basic/service/h_whohas.c b/src/bacnet/basic/service/h_whohas.c index 276678d2..c0796dd7 100644 --- a/src/bacnet/basic/service/h_whohas.c +++ b/src/bacnet/basic/service/h_whohas.c @@ -113,7 +113,7 @@ void handler_who_has_for_routing( BACNET_WHO_HAS_DATA data; int32_t dev_instance; int cursor = 0; /* Starting hint */ - int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ + int32_t my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ BACNET_ADDRESS bcast_net; (void)src; diff --git a/src/bacnet/basic/service/h_whois.c b/src/bacnet/basic/service/h_whois.c index da54356c..52d282b0 100644 --- a/src/bacnet/basic/service/h_whois.c +++ b/src/bacnet/basic/service/h_whois.c @@ -160,7 +160,7 @@ static void check_who_is_for_routing( int32_t high_limit = 0; int32_t dev_instance; int cursor = 0; /* Starting hint */ - int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ + int32_t my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ BACNET_ADDRESS bcast_net; len = whois_decode_service_request(