Fix type limits for uint32_t in sscanf and printf across multiple files (#1298)
This commit is contained in:
+9
-7
@@ -4712,7 +4712,8 @@ special_event_from_ascii(BACNET_APPLICATION_DATA_VALUE *value, char *str)
|
|||||||
char *period_str, *sched_str, *prio_str;
|
char *period_str, *sched_str, *prio_str;
|
||||||
BACNET_SPECIAL_EVENT *ev = &value->type.Special_Event;
|
BACNET_SPECIAL_EVENT *ev = &value->type.Special_Event;
|
||||||
BACNET_UNSIGNED_INTEGER prio = 0;
|
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 type_buf[64];
|
||||||
char *colon;
|
char *colon;
|
||||||
size_t tlen;
|
size_t tlen;
|
||||||
@@ -4776,19 +4777,20 @@ special_event_from_ascii(BACNET_APPLICATION_DATA_VALUE *value, char *str)
|
|||||||
}
|
}
|
||||||
memcpy(type_buf, period_str, tlen);
|
memcpy(type_buf, period_str, tlen);
|
||||||
type_buf[tlen] = '\0';
|
type_buf[tlen] = '\0';
|
||||||
count = sscanf(colon + 1, "%7u", &obj_instance);
|
count = sscanf(colon + 1, "%7lu", &unsigned_value);
|
||||||
if (count != 1) {
|
if (count != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ev->period.calendarReference.instance = obj_instance;
|
ev->period.calendarReference.instance = (uint32_t)unsigned_value;
|
||||||
if (bactext_object_type_strtol(type_buf, &obj_type)) {
|
if (bactext_object_type_strtol(type_buf, &found_index)) {
|
||||||
ev->period.calendarReference.type = (BACNET_OBJECT_TYPE)obj_type;
|
ev->period.calendarReference.type = (BACNET_OBJECT_TYPE)found_index;
|
||||||
} else {
|
} else {
|
||||||
count = sscanf(type_buf, "%4u", &obj_type);
|
count = sscanf(type_buf, "%4lu", &unsigned_value);
|
||||||
if (count != 1) {
|
if (count != 1) {
|
||||||
return false;
|
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;
|
value->tag = BACNET_APPLICATION_TAG_SPECIAL_EVENT;
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ bool Time_Value_Object_Name(
|
|||||||
{
|
{
|
||||||
bool status = false;
|
bool status = false;
|
||||||
struct object_data *pObject;
|
struct object_data *pObject;
|
||||||
char name_text[16] = "Time-4194303";
|
char name_text[32] = "";
|
||||||
|
|
||||||
pObject = Keylist_Data(Object_List, object_instance);
|
pObject = Keylist_Data(Object_List, object_instance);
|
||||||
if (pObject) {
|
if (pObject) {
|
||||||
@@ -400,7 +400,9 @@ bool Time_Value_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), "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);
|
status = characterstring_init_ansi(object_name, name_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,13 +39,20 @@ void ge_ack_print_data(
|
|||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
BACNET_GET_EVENT_INFORMATION_DATA *act_data = data;
|
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("DeviceID\tType\tInstance\teventState\n");
|
||||||
printf("--------------- ------- --------------- ---------------\n");
|
printf("--------------- ------- --------------- ---------------\n");
|
||||||
while (act_data) {
|
while (act_data) {
|
||||||
|
if (act_data->eventState < EVENT_STATE_MAX) {
|
||||||
|
state_str = state_strs[act_data->eventState];
|
||||||
|
} else {
|
||||||
|
state_str = "??";
|
||||||
|
}
|
||||||
printf(
|
printf(
|
||||||
"%u\t\t%u\t%u\t\t%s\n", device_id, act_data->objectIdentifier.type,
|
"%lu\t\t%u\t%lu\t\t%s\n", (unsigned long)device_id,
|
||||||
act_data->objectIdentifier.instance, state_strs[data->eventState]);
|
act_data->objectIdentifier.type,
|
||||||
|
(unsigned long)act_data->objectIdentifier.instance, state_str);
|
||||||
act_data = act_data->next;
|
act_data = act_data->next;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user