Fix datatype conversion errors found by splint. Fix Binary input/value set. (#672)

This commit is contained in:
Steve Karg
2024-06-12 21:13:33 -05:00
committed by GitHub
parent aa9370004b
commit 12d55ab3cb
6 changed files with 382 additions and 196 deletions
+29 -30
View File
@@ -51,12 +51,14 @@ struct object_data {
/* Key List for storing the object data sorted by instance number */
static OS_Keylist Object_List;
/* callback for present value writes */
static calendar_write_present_value_callback Calendar_Write_Present_Value_Callback;
static calendar_write_present_value_callback
Calendar_Write_Present_Value_Callback;
/* These three arrays are used by the ReadPropertyMultiple handler */
static const int Calendar_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, PROP_DATE_LIST,
-1 };
static const int Calendar_Properties_Required[] = {
PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE,
PROP_PRESENT_VALUE, PROP_DATE_LIST, -1
};
static const int Calendar_Properties_Optional[] = { PROP_DESCRIPTION, -1 };
@@ -64,8 +66,8 @@ static const int Calendar_Properties_Proprietary[] = { -1 };
/* standard properties that are arrays for this object,
but not necessary supported in this object */
static const int BACnetARRAY_Properties[] = {
PROP_PRIORITY_ARRAY, PROP_TAGS, -1 };
static const int BACnetARRAY_Properties[] = { PROP_PRIORITY_ARRAY, PROP_TAGS,
-1 };
/**
* Returns the list of required, optional, and proprietary properties.
@@ -166,7 +168,8 @@ unsigned Calendar_Instance_To_Index(uint32_t object_instance)
*
* @return true if values are within range and present-value is set.
*/
static bool Calendar_Present_Value_Write(uint32_t object_instance,
static bool Calendar_Present_Value_Write(
uint32_t object_instance,
bool old_value,
bool value,
uint8_t priority,
@@ -220,8 +223,8 @@ static void Calendar_Date_List_Clean(OS_Keylist list)
*
* @return Calendar entity.
*/
BACNET_CALENDAR_ENTRY *Calendar_Date_List_Get(
uint32_t object_instance, uint8_t index)
BACNET_CALENDAR_ENTRY *
Calendar_Date_List_Get(uint32_t object_instance, uint8_t index)
{
BACNET_CALENDAR_ENTRY *entry = NULL;
struct object_data *pObject;
@@ -242,8 +245,8 @@ BACNET_CALENDAR_ENTRY *Calendar_Date_List_Get(
*
* @return true if the entity is add successfully.
*/
bool Calendar_Date_List_Add(uint32_t object_instance,
BACNET_CALENDAR_ENTRY *value)
bool Calendar_Date_List_Add(
uint32_t object_instance, BACNET_CALENDAR_ENTRY *value)
{
bool st = false;
BACNET_CALENDAR_ENTRY *entry;
@@ -253,7 +256,7 @@ bool Calendar_Date_List_Add(uint32_t object_instance,
if (!pObject) {
return false;
}
entry = calloc(1, sizeof(BACNET_CALENDAR_ENTRY));
if (!entry) {
return false;
@@ -381,7 +384,7 @@ bool Calendar_Object_Name(
{
bool status = false;
struct object_data *pObject;
char name_text[16] = "CALENDAR-4194303";
char name_text[32] = "CALENDAR-4194303";
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
@@ -389,7 +392,8 @@ bool Calendar_Object_Name(
status =
characterstring_init_ansi(object_name, pObject->Object_Name);
} else {
snprintf(name_text, sizeof(name_text), "CALENDAR-%u", object_instance);
snprintf(
name_text, sizeof(name_text), "CALENDAR-%u", object_instance);
status = characterstring_init_ansi(object_name, name_text);
}
}
@@ -471,11 +475,9 @@ bool Calendar_Description_Set(uint32_t object_instance, char *new_name)
* @param object_property - object-property to be checked
* @return true if the property is a BACnetARRAY property
*/
static bool BACnetARRAY_Property(
int object_property)
static bool BACnetARRAY_Property(int object_property)
{
return property_list_member(
BACnetARRAY_Properties, object_property);
return property_list_member(BACnetARRAY_Properties, object_property);
}
/**
@@ -537,8 +539,7 @@ int Calendar_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
break;
}
/* only array properties can have array options */
if ((apdu_len >= 0) &&
(!BACnetARRAY_Property(rpdata->object_property)) &&
if ((apdu_len >= 0) && (!BACnetARRAY_Property(rpdata->object_property)) &&
(rpdata->array_index != BACNET_ARRAY_ALL)) {
rpdata->error_class = ERROR_CLASS_PROPERTY;
rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
@@ -593,8 +594,7 @@ bool Calendar_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
while (iOffset < wp_data->application_data_len) {
len = bacnet_calendar_entry_decode(
&wp_data->application_data[iOffset],
wp_data->application_data_len - iOffset,
&entry);
wp_data->application_data_len - iOffset, &entry);
if (len == BACNET_STATUS_REJECT) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE;
@@ -604,16 +604,15 @@ bool Calendar_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
Calendar_Date_List_Add(wp_data->object_instance, &entry);
}
pv = Calendar_Present_Value(wp_data->object_instance);
status = Calendar_Present_Value_Write(wp_data->object_instance,
pv_old, pv, wp_data->priority, &wp_data->error_class,
&wp_data->error_code);
status = Calendar_Present_Value_Write(
wp_data->object_instance, pv_old, pv, wp_data->priority,
&wp_data->error_class, &wp_data->error_code);
break;
default:
if (property_lists_member(
Calendar_Properties_Required,
Calendar_Properties_Optional,
Calendar_Properties_Proprietary,
wp_data->object_property)) {
Calendar_Properties_Required, Calendar_Properties_Optional,
Calendar_Properties_Proprietary,
wp_data->object_property)) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
} else {
@@ -710,7 +709,7 @@ uint32_t Calendar_Create(uint32_t object_instance)
}
pObject->Object_Name = NULL;
pObject->Description = NULL;
pObject->Present_Value = false;
pObject->Present_Value = false;
pObject->Date_List = Keylist_Create();
pObject->Changed = false;
pObject->Write_Enabled = false;