Fix type limits for uint32_t in sscanf and printf across multiple files (#1298)

This commit is contained in:
Steve Karg
2026-04-08 16:35:31 -05:00
committed by GitHub
parent ad89cba29b
commit 7536c6b6fa
3 changed files with 23 additions and 12 deletions
+9 -7
View File
@@ -4712,7 +4712,8 @@ special_event_from_ascii(BACNET_APPLICATION_DATA_VALUE *value, char *str)
char *period_str, *sched_str, *prio_str;
BACNET_SPECIAL_EVENT *ev = &value->type.Special_Event;
BACNET_UNSIGNED_INTEGER prio = 0;
uint32_t obj_type = 0, obj_instance = 0;
long unsigned int unsigned_value = 0;
uint32_t found_index = 0;
char type_buf[64];
char *colon;
size_t tlen;
@@ -4776,19 +4777,20 @@ special_event_from_ascii(BACNET_APPLICATION_DATA_VALUE *value, char *str)
}
memcpy(type_buf, period_str, tlen);
type_buf[tlen] = '\0';
count = sscanf(colon + 1, "%7u", &obj_instance);
count = sscanf(colon + 1, "%7lu", &unsigned_value);
if (count != 1) {
return false;
}
ev->period.calendarReference.instance = obj_instance;
if (bactext_object_type_strtol(type_buf, &obj_type)) {
ev->period.calendarReference.type = (BACNET_OBJECT_TYPE)obj_type;
ev->period.calendarReference.instance = (uint32_t)unsigned_value;
if (bactext_object_type_strtol(type_buf, &found_index)) {
ev->period.calendarReference.type = (BACNET_OBJECT_TYPE)found_index;
} else {
count = sscanf(type_buf, "%4u", &obj_type);
count = sscanf(type_buf, "%4lu", &unsigned_value);
if (count != 1) {
return false;
}
ev->period.calendarReference.type = (BACNET_OBJECT_TYPE)obj_type;
ev->period.calendarReference.type =
(BACNET_OBJECT_TYPE)unsigned_value;
}
}
value->tag = BACNET_APPLICATION_TAG_SPECIAL_EVENT;
+4 -2
View File
@@ -392,7 +392,7 @@ bool Time_Value_Object_Name(
{
bool status = false;
struct object_data *pObject;
char name_text[16] = "Time-4194303";
char name_text[32] = "";
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
@@ -400,7 +400,9 @@ bool Time_Value_Object_Name(
status =
characterstring_init_ansi(object_name, pObject->Object_Name);
} else {
snprintf(name_text, sizeof(name_text), "Time-%u", object_instance);
snprintf(
name_text, sizeof(name_text), "Time-Value-%lu",
(unsigned long)object_instance);
status = characterstring_init_ansi(object_name, name_text);
}
}
+10 -3
View File
@@ -39,13 +39,20 @@ void ge_ack_print_data(
{
unsigned int count = 0;
BACNET_GET_EVENT_INFORMATION_DATA *act_data = data;
const char *state_strs[] = { "NO", "FA", "ON", "HL", "LL" };
const char *state_strs[EVENT_STATE_MAX] = { "NO", "FA", "ON", "HL", "LL" };
const char *state_str;
printf("DeviceID\tType\tInstance\teventState\n");
printf("--------------- ------- --------------- ---------------\n");
while (act_data) {
if (act_data->eventState < EVENT_STATE_MAX) {
state_str = state_strs[act_data->eventState];
} else {
state_str = "??";
}
printf(
"%u\t\t%u\t%u\t\t%s\n", device_id, act_data->objectIdentifier.type,
act_data->objectIdentifier.instance, state_strs[data->eventState]);
"%lu\t\t%u\t%lu\t\t%s\n", (unsigned long)device_id,
act_data->objectIdentifier.type,
(unsigned long)act_data->objectIdentifier.instance, state_str);
act_data = act_data->next;
count++;
}