Refactored all the sprintf to use snprintf instead. (#628)
This commit is contained in:
@@ -136,13 +136,13 @@ unsigned Accumulator_Instance_To_Index(uint32_t object_instance)
|
||||
bool Accumulator_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32]; /* okay for single thread */
|
||||
static char text[32]; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCUMULATORS) {
|
||||
sprintf(
|
||||
text_string, "ACCUMULATOR-%lu", (long unsigned int)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text),
|
||||
"ACCUMULATOR-%lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -139,13 +139,13 @@ unsigned Access_Credential_Instance_To_Index(uint32_t object_instance)
|
||||
bool Access_Credential_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_CREDENTIALS) {
|
||||
sprintf(text_string, "ACCESS CREDENTIAL %lu",
|
||||
snprintf(text, sizeof(text), "ACCESS CREDENTIAL %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -276,12 +276,13 @@ static int Access_Door_Priority_Array_Encode(
|
||||
bool Access_Door_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_DOORS) {
|
||||
sprintf(text_string, "ACCESS DOOR %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "ACCESS DOOR %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -142,13 +142,13 @@ unsigned Access_Point_Instance_To_Index(uint32_t object_instance)
|
||||
bool Access_Point_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_POINTS) {
|
||||
sprintf(
|
||||
text_string, "ACCESS POINT %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "ACCESS POINT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -134,13 +134,13 @@ unsigned Access_Rights_Instance_To_Index(uint32_t object_instance)
|
||||
bool Access_Rights_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_RIGHTSS) {
|
||||
sprintf(
|
||||
text_string, "ACCESS RIGHTS %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "ACCESS RIGHTS %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -131,12 +131,13 @@ unsigned Access_User_Instance_To_Index(uint32_t object_instance)
|
||||
bool Access_User_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_USERS) {
|
||||
sprintf(text_string, "ACCESS USER %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "ACCESS USER %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -136,12 +136,13 @@ unsigned Access_Zone_Instance_To_Index(uint32_t object_instance)
|
||||
bool Access_Zone_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_ACCESS_ZONES) {
|
||||
sprintf(text_string, "ACCESS ZONE %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "ACCESS ZONE %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -464,16 +464,16 @@ static bool Binary_Input_Present_Value_Write(
|
||||
bool Binary_Input_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Binary_Input_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Name == NULL) {
|
||||
sprintf(
|
||||
text_string, "BINARY INPUT %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "BINARY INPUT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
} else {
|
||||
status = characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
}
|
||||
|
||||
@@ -464,16 +464,16 @@ static bool Binary_Value_Present_Value_Write(uint32_t object_instance,
|
||||
bool Binary_Value_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
struct object_data *pObject;
|
||||
|
||||
pObject = Binary_Value_Object(object_instance);
|
||||
if (pObject) {
|
||||
if (pObject->Object_Name == NULL) {
|
||||
sprintf(text_string, "BINARY INPUT %lu",
|
||||
snprintf(text, sizeof(text), "BINARY INPUT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
} else {
|
||||
status =
|
||||
characterstring_init_ansi(object_name, pObject->Object_Name);
|
||||
|
||||
@@ -599,14 +599,15 @@ bool Command_All_Writes_Successful_Set(uint32_t object_instance, bool value)
|
||||
bool Command_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
unsigned int index;
|
||||
bool status = false;
|
||||
|
||||
index = Command_Instance_To_Index(object_instance);
|
||||
if (index < MAX_COMMANDS) {
|
||||
sprintf(text_string, "COMMAND %lu", (unsigned long)index);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "COMMAND %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -138,13 +138,13 @@ unsigned Credential_Data_Input_Instance_To_Index(uint32_t object_instance)
|
||||
bool Credential_Data_Input_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_CREDENTIAL_DATA_INPUTS) {
|
||||
sprintf(text_string, "CREDENTIAL DATA INPUT %lu",
|
||||
snprintf(text, sizeof(text), "CREDENTIAL DATA INPUT %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -214,15 +214,15 @@ bool Integer_Value_Present_Value_Set(
|
||||
bool Integer_Value_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
char text_string[32] = "";
|
||||
char text[32] = "";
|
||||
unsigned int index;
|
||||
bool status = false;
|
||||
|
||||
index = Integer_Value_Instance_To_Index(object_instance);
|
||||
if (index < MAX_INTEGER_VALUES) {
|
||||
sprintf(
|
||||
text_string, "INTEGER VALUE %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "INTEGER VALUE %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -252,12 +252,12 @@ static BACNET_SHED_STATE Load_Control_Present_Value(uint32_t object_instance)
|
||||
bool Load_Control_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_LOAD_CONTROLS) {
|
||||
sprintf(text_string, "LOAD CONTROL %u", object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "LOAD CONTROL %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -151,14 +151,15 @@ unsigned Notification_Class_Instance_To_Index(uint32_t object_instance)
|
||||
bool Notification_Class_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
unsigned int index;
|
||||
bool status = false;
|
||||
|
||||
index = Notification_Class_Instance_To_Index(object_instance);
|
||||
if (index < MAX_NOTIFICATION_CLASSES) {
|
||||
sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long)index);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "NOTIFICATION CLASS %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -165,13 +165,13 @@ BACNET_OCTET_STRING *OctetString_Value_Present_Value(uint32_t object_instance)
|
||||
bool OctetString_Value_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_OCTETSTRING_VALUES) {
|
||||
sprintf(text_string, "OCTETSTRING VALUE %lu",
|
||||
snprintf(text, sizeof(text), "OCTETSTRING VALUE %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -166,13 +166,13 @@ uint32_t PositiveInteger_Value_Present_Value(uint32_t object_instance)
|
||||
bool PositiveInteger_Value_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_POSITIVEINTEGER_VALUES) {
|
||||
sprintf(text_string, "POSITIVEINTEGER VALUE %lu",
|
||||
snprintf(text, sizeof(text), "POSITIVEINTEGER VALUE %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -130,14 +130,14 @@ unsigned Schedule_Instance_To_Index(uint32_t instance)
|
||||
bool Schedule_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
unsigned int index;
|
||||
bool status = false;
|
||||
|
||||
index = Schedule_Instance_To_Index(object_instance);
|
||||
if (index < MAX_SCHEDULES) {
|
||||
sprintf(text_string, "SCHEDULE %lu", (unsigned long)index);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "SCHEDULE %lu", (unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -248,12 +248,13 @@ void Trend_Log_Init(void)
|
||||
bool Trend_Log_Object_Name(
|
||||
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name)
|
||||
{
|
||||
static char text_string[32] = ""; /* okay for single thread */
|
||||
static char text[32] = ""; /* okay for single thread */
|
||||
bool status = false;
|
||||
|
||||
if (object_instance < MAX_TREND_LOGS) {
|
||||
sprintf(text_string, "Trend Log %u", object_instance);
|
||||
status = characterstring_init_ansi(object_name, text_string);
|
||||
snprintf(text, sizeof(text), "Trend Log %lu",
|
||||
(unsigned long)object_instance);
|
||||
status = characterstring_init_ansi(object_name, text);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -65,9 +65,9 @@ void debug_printf(const char *format, ...)
|
||||
BACNET_DATE date;
|
||||
BACNET_TIME time;
|
||||
datetime_local(&date, &time, NULL, NULL);
|
||||
sprintf(stamp_str, "[%02d:%02d:%02d.%03d]: ", time.hour, time.min,
|
||||
time.sec, time.hundredths * 10);
|
||||
|
||||
snprintf(
|
||||
stamp_str, sizeof(stamp_str), "[%02d:%02d:%02d.%03d]: ", time.hour,
|
||||
time.min, time.sec, time.hundredths * 10);
|
||||
va_start(ap, format);
|
||||
vsprintf(buf, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
Reference in New Issue
Block a user