Fixed compiler warning format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=] by casting or increasing format specifier size and casting. (#1092)

* Fixed compiler warning format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=] by casting or increasing format specifier size and casting. Increased the size of the name string to handle larger possible integers.

* Fixed copied code that no longer needs static function scope variables for text names.
This commit is contained in:
Steve Karg
2025-09-12 15:08:47 -05:00
committed by GitHub
parent 0da61e52bb
commit 9b6173995c
28 changed files with 82 additions and 64 deletions
+10
View File
@@ -22,6 +22,7 @@ The git repositories are hosted at the following sites:
### Added ### Added
* Added MS/TP statistics counters for BadCRC and Poll-For-Master. (#1081)
* Added Lighting Output API to implement override for HOA control. * Added Lighting Output API to implement override for HOA control.
Integrated lighting command overridden behavior into the lighting Integrated lighting command overridden behavior into the lighting
output object and added Overridden status flags API. output object and added Overridden status flags API.
@@ -99,6 +100,9 @@ The git repositories are hosted at the following sites:
### Changed ### Changed
* Changed Who-Am-I and You-Are JSON handlers to eliminate dynamic
memory allocation for model and serial number strings,
improving memory management and simplifying code. (#1089)
* Change stm32f4xx example to use static RAM file system. (#1058) * Change stm32f4xx example to use static RAM file system. (#1058)
* Changed the bacnet file object to be storage agnostic by refactoring * Changed the bacnet file object to be storage agnostic by refactoring
and using callbacks. (#1056) and using callbacks. (#1056)
@@ -110,6 +114,12 @@ The git repositories are hosted at the following sites:
### Fixed ### Fixed
* Fixed copied code that no longer needs static function scope variables
for text names. (#1092)
* Fixed compiler warning format '%u' expects argument of type 'unsigned int',
but argument 4 has type 'uint32_t' {aka 'long unsigned int'}
[-Werror=format=] by casting or increasing format specifier size
and casting. (#1092)
* Fixed Lighting_Command to ignore write priority and use its own. (#1086) * Fixed Lighting_Command to ignore write priority and use its own. (#1086)
* Fixed BACnetLightingOperation reserved range. (#1086) * Fixed BACnetLightingOperation reserved range. (#1086)
* Fixed missing prototype warning in lighting.c module. * Fixed missing prototype warning in lighting.c module.
+2 -1
View File
@@ -683,7 +683,8 @@ static void PrintReadPropertyData(
static void Print_Property_Identifier(unsigned propertyIdentifier) static void Print_Property_Identifier(unsigned propertyIdentifier)
{ {
if (bactext_property_name_proprietary(propertyIdentifier)) { if (bactext_property_name_proprietary(propertyIdentifier)) {
fprintf(stdout, "-- proprietary %u", propertyIdentifier); fprintf(
stdout, "-- proprietary %lu", (unsigned long)propertyIdentifier);
} else { } else {
fprintf(stdout, "%s", bactext_property_name(propertyIdentifier)); fprintf(stdout, "%s", bactext_property_name(propertyIdentifier));
} }
+3 -1
View File
@@ -274,7 +274,9 @@ static void add_discovered_properties_to_gui(
bacnet_discover_object_property_identifier( bacnet_discover_object_property_identifier(
device_id, object_type, object_instance, index, &property_id); device_id, object_type, object_instance, index, &property_id);
if (bactext_property_name_proprietary(property_id)) { if (bactext_property_name_proprietary(property_id)) {
asprintfa(&property_string, "proprietary-%u", property_id); asprintfa(
&property_string, "proprietary-%lu",
(unsigned long)property_id);
} else { } else {
asprintfa( asprintfa(
&property_string, "%s", bactext_property_name(property_id)); &property_string, "%s", bactext_property_name(property_id));
+1 -1
View File
@@ -75,7 +75,7 @@ uint32_t Analog_Input_Index_To_Instance(unsigned index)
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text_string[16] = "AI-0"; /* okay for single thread */ char text_string[16] = "AI-0";
bool status = false; bool status = false;
if (object_instance < MAX_ANALOG_INPUTS) { if (object_instance < MAX_ANALOG_INPUTS) {
+1 -1
View File
@@ -131,7 +131,7 @@ float Analog_Value_Present_Value(uint32_t object_instance)
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text_string[16] = "AV-0"; /* okay for single thread */ char text_string[16] = "AV-0";
bool status = false; bool status = false;
if (object_instance < MAX_ANALOG_VALUES) { if (object_instance < MAX_ANALOG_VALUES) {
+1 -1
View File
@@ -110,7 +110,7 @@ BACNET_BINARY_PV Binary_Input_Present_Value(uint32_t object_instance)
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text_string[16] = "BI-0"; /* okay for single thread */ char text_string[16] = "BI-0";
bool status = false; bool status = false;
if (object_instance < MAX_BINARY_INPUTS) { if (object_instance < MAX_BINARY_INPUTS) {
+1 -1
View File
@@ -105,7 +105,7 @@ BACNET_BINARY_PV Binary_Value_Present_Value(uint32_t object_instance)
bool Binary_Value_Object_Name( bool Binary_Value_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text_string[16] = "BV-0"; /* okay for single thread */ char text_string[16] = "BV-0";
bool status = false; bool status = false;
if (object_instance < MAX_BINARY_VALUES) { if (object_instance < MAX_BINARY_VALUES) {
+1 -1
View File
@@ -77,7 +77,7 @@ uint32_t Analog_Input_Index_To_Instance(unsigned index)
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text[32]; /* okay for single thread */ char text[32];
bool status = false; bool status = false;
if (object_instance < MAX_ANALOG_INPUTS) { if (object_instance < MAX_ANALOG_INPUTS) {
+1 -1
View File
@@ -141,7 +141,7 @@ bool Analog_Value_Present_Value_Set(
bool Analog_Value_Object_Name( bool Analog_Value_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text[32] = ""; /* okay for single thread */ char text[32] = "";
unsigned index = 0; unsigned index = 0;
bool status = false; bool status = false;
+1 -1
View File
@@ -122,7 +122,7 @@ bool Binary_Input_Present_Value_Set(
bool Binary_Input_Object_Name( bool Binary_Input_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text[32]; /* okay for single thread */ char text[32];
bool status = false; bool status = false;
if (object_instance < MAX_BINARY_INPUTS) { if (object_instance < MAX_BINARY_INPUTS) {
+1 -1
View File
@@ -192,7 +192,7 @@ bool Binary_Output_Out_Of_Service(uint32_t instance)
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text[32]; /* okay for single thread */ char text[32];
bool status = false; bool status = false;
if (object_instance < MAX_BINARY_OUTPUTS) { if (object_instance < MAX_BINARY_OUTPUTS) {
+1 -1
View File
@@ -181,7 +181,7 @@ bool Binary_Output_Out_Of_Service(uint32_t instance)
bool Binary_Output_Object_Name( bool Binary_Output_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text_string[16] = "BO-0"; /* okay for single thread */ char text_string[16] = "BO-0";
bool status = false; bool status = false;
if (object_instance < MAX_BINARY_OUTPUTS) { if (object_instance < MAX_BINARY_OUTPUTS) {
+1 -1
View File
@@ -93,7 +93,7 @@ void bip6_set_interface(char *ifname)
Hints.ai_socktype = SOCK_DGRAM; Hints.ai_socktype = SOCK_DGRAM;
Hints.ai_protocol = IPPROTO_UDP; Hints.ai_protocol = IPPROTO_UDP;
Hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE; Hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE;
snprintf(port, sizeof(port), "%u", BIP6_Addr.port); snprintf(port, sizeof(port), "%u", (unsigned)BIP6_Addr.port);
if (BIP6_Debug) { if (BIP6_Debug) {
debug_fprintf( debug_fprintf(
stderr, "BIP6: seeking IPv6 address %s port %s...\n", ifname, port); stderr, "BIP6: seeking IPv6 address %s port %s...\n", ifname, port);
+1 -1
View File
@@ -86,7 +86,7 @@ unsigned Analog_Input_Count(void)
bool Analog_Input_Object_Name( bool Analog_Input_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
static char text[32]; /* okay for single thread */ char text[32];
bool status = false; bool status = false;
unsigned index = 0; unsigned index = 0;
+2 -2
View File
@@ -495,8 +495,8 @@ bool BitString_Value_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "BITSTRING_VALUE-%u", name_text, sizeof(name_text), "BITSTRING_VALUE-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+3 -3
View File
@@ -773,7 +773,7 @@ bool Binary_Lighting_Output_Object_Name(
{ {
bool status = false; bool status = false;
struct object_data *pObject; struct object_data *pObject;
char name_text[32] = "BINARY-LIGHTING-OUTPUT-4194303"; char name_text[48] = "BINARY-LIGHTING-OUTPUT-4194303";
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
@@ -782,8 +782,8 @@ bool Binary_Lighting_Output_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "BINARY-LIGHTING-OUTPUT-%u", name_text, sizeof(name_text), "BINARY-LIGHTING-OUTPUT-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+2 -1
View File
@@ -384,7 +384,8 @@ bool Calendar_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "CALENDAR-%u", object_instance); name_text, sizeof(name_text), "CALENDAR-%lu",
(unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+1 -1
View File
@@ -847,7 +847,7 @@ bool Channel_Object_Name(
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
{ {
bool status = false; bool status = false;
char name_text[24] = "CHANNEL-4194303"; char name_text[32] = "CHANNEL-4194303";
struct object_data *pObject; struct object_data *pObject;
pObject = Object_Data(object_instance); pObject = Object_Data(object_instance);
+4 -2
View File
@@ -696,7 +696,7 @@ bool Color_Object_Name(
{ {
bool status = false; bool status = false;
struct object_data *pObject; struct object_data *pObject;
char name_text[24] = "COLOR-4194303"; char name_text[32] = "COLOR-4194303";
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
@@ -704,7 +704,9 @@ bool Color_Object_Name(
status = status =
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf(name_text, sizeof(name_text), "COLOR-%u", object_instance); snprintf(
name_text, sizeof(name_text), "COLOR-%lu",
(unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+3 -3
View File
@@ -935,7 +935,7 @@ bool Color_Temperature_Object_Name(
{ {
bool status = false; bool status = false;
struct object_data *pObject; struct object_data *pObject;
char name_text[26] = "COLOR-TEMPERATURE-4194303"; char name_text[48] = "COLOR-TEMPERATURE-4194303";
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
@@ -944,8 +944,8 @@ bool Color_Temperature_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "COLOR-TEMPERATURE-%u", name_text, sizeof(name_text), "COLOR-TEMPERATURE-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+2 -2
View File
@@ -244,8 +244,8 @@ bool Load_Control_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "LOAD_CONTROL-%u", name_text, sizeof(name_text), "LOAD_CONTROL-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+3 -3
View File
@@ -974,7 +974,7 @@ bool Lighting_Output_Object_Name(
{ {
bool status = false; bool status = false;
struct object_data *pObject; struct object_data *pObject;
char name_text[24] = "LIGHTING-OUTPUT-4194303"; char name_text[48] = "LIGHTING-OUTPUT-4194303";
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
@@ -983,8 +983,8 @@ bool Lighting_Output_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "LIGHTING-OUTPUT-%u", name_text, sizeof(name_text), "LIGHTING-OUTPUT-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+2 -2
View File
@@ -198,8 +198,8 @@ bool Life_Safety_Point_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "LIFE-SAFETY-POINT-%u", name_text, sizeof(name_text), "LIFE-SAFETY-POINT-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+2 -2
View File
@@ -209,8 +209,8 @@ bool Life_Safety_Zone_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "LIFE-SAFETY-ZONE-%u", name_text, sizeof(name_text), "LIFE-SAFETY-ZONE-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+3 -3
View File
@@ -168,7 +168,7 @@ bool Structured_View_Object_Name(
{ {
bool status = false; bool status = false;
struct object_data *pObject; struct object_data *pObject;
char name_text[24] = "Structured-View-4194303"; char name_text[48] = "Structured-View-4194303";
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
@@ -177,8 +177,8 @@ bool Structured_View_Object_Name(
characterstring_init_ansi(object_name, pObject->Object_Name); characterstring_init_ansi(object_name, pObject->Object_Name);
} else { } else {
snprintf( snprintf(
name_text, sizeof(name_text), "Structured-View-%u", name_text, sizeof(name_text), "Structured-View-%lu",
object_instance); (unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text); status = characterstring_init_ansi(object_name, name_text);
} }
} }
+1 -1
View File
@@ -51,7 +51,7 @@ static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data)
by others subject to the procedures and by others subject to the procedures and
constraints described in Clause 23. */ constraints described in Clause 23. */
debug_printf_stdout( debug_printf_stdout(
" proprietary %u", (unsigned)data->object_property); " proprietary %lu", (unsigned long)data->object_property);
} }
if (data->array_index == BACNET_ARRAY_ALL) { if (data->array_index == BACNET_ARRAY_ALL) {
debug_printf_stdout(": "); debug_printf_stdout(": ");
+27 -25
View File
@@ -949,42 +949,44 @@ int bacnet_bdt_entry_to_ascii(
if (ip_len == 4) { if (ip_len == 4) {
len = snprintf( len = snprintf(
str, str_size, "%u.%u.%u.%u:%u,%u.%u.%u.%u", str, str_size, "%u.%u.%u.%u:%u,%u.%u.%u.%u",
value->bbmd_address.host.ip_address.value[0], (unsigned)value->bbmd_address.host.ip_address.value[0],
value->bbmd_address.host.ip_address.value[1], (unsigned)value->bbmd_address.host.ip_address.value[1],
value->bbmd_address.host.ip_address.value[2], (unsigned)value->bbmd_address.host.ip_address.value[2],
value->bbmd_address.host.ip_address.value[3], (unsigned)value->bbmd_address.host.ip_address.value[3],
value->bbmd_address.port, value->broadcast_mask.value[0], (unsigned)value->bbmd_address.port,
value->broadcast_mask.value[1], value->broadcast_mask.value[2], (unsigned)value->broadcast_mask.value[0],
value->broadcast_mask.value[3]); (unsigned)value->broadcast_mask.value[1],
(unsigned)value->broadcast_mask.value[2],
(unsigned)value->broadcast_mask.value[3]);
} else if (ip_len == 16) { } else if (ip_len == 16) {
len = snprintf( len = snprintf(
str, str_size, str, str_size,
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:" "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%u", "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%u",
value->bbmd_address.host.ip_address.value[0], (unsigned)value->bbmd_address.host.ip_address.value[0],
value->bbmd_address.host.ip_address.value[1], (unsigned)value->bbmd_address.host.ip_address.value[1],
value->bbmd_address.host.ip_address.value[2], (unsigned)value->bbmd_address.host.ip_address.value[2],
value->bbmd_address.host.ip_address.value[3], (unsigned)value->bbmd_address.host.ip_address.value[3],
value->bbmd_address.host.ip_address.value[4], (unsigned)value->bbmd_address.host.ip_address.value[4],
value->bbmd_address.host.ip_address.value[5], (unsigned)value->bbmd_address.host.ip_address.value[5],
value->bbmd_address.host.ip_address.value[6], (unsigned)value->bbmd_address.host.ip_address.value[6],
value->bbmd_address.host.ip_address.value[7], (unsigned)value->bbmd_address.host.ip_address.value[7],
value->bbmd_address.host.ip_address.value[8], (unsigned)value->bbmd_address.host.ip_address.value[8],
value->bbmd_address.host.ip_address.value[9], (unsigned)value->bbmd_address.host.ip_address.value[9],
value->bbmd_address.host.ip_address.value[10], (unsigned)value->bbmd_address.host.ip_address.value[10],
value->bbmd_address.host.ip_address.value[11], (unsigned)value->bbmd_address.host.ip_address.value[11],
value->bbmd_address.host.ip_address.value[12], (unsigned)value->bbmd_address.host.ip_address.value[12],
value->bbmd_address.host.ip_address.value[13], (unsigned)value->bbmd_address.host.ip_address.value[13],
value->bbmd_address.host.ip_address.value[14], (unsigned)value->bbmd_address.host.ip_address.value[14],
value->bbmd_address.host.ip_address.value[15], (unsigned)value->bbmd_address.host.ip_address.value[15],
value->bbmd_address.port); (unsigned)value->bbmd_address.port);
} }
} else if (value->bbmd_address.host_name) { } else if (value->bbmd_address.host_name) {
len = snprintf( len = snprintf(
str, str_size, "%*s:%u", str, str_size, "%*s:%u",
(int)characterstring_length(&value->bbmd_address.host.name), (int)characterstring_length(&value->bbmd_address.host.name),
characterstring_value(&value->bbmd_address.host.name), characterstring_value(&value->bbmd_address.host.name),
value->bbmd_address.port); (unsigned)value->bbmd_address.port);
} }
return len; return len;
+1 -1
View File
@@ -440,7 +440,7 @@ int lighting_command_to_ascii(
priority = value->priority; priority = value->priority;
} }
len = snprintf( len = snprintf(
buf, buf_size, "%u,%f,%lu,%u", value->operation, buf, buf_size, "%u,%f,%lu,%u", (unsigned)value->operation,
(double)target_level, (unsigned long)fade_time, (double)target_level, (unsigned long)fade_time,
(unsigned)priority); (unsigned)priority);
break; break;