From 5a3c2285ef6bd1d587b3e7fee40a486f269d3f9c Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 19 Mar 2024 21:26:00 +0000 Subject: [PATCH] - IED 61850 server: fixed bug creating arrays of data objects --- src/iec61850/server/model/dynamic_model.c | 23 +++++++++++++---------- src/iec61850/server/model/model.c | 6 ++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/iec61850/server/model/dynamic_model.c b/src/iec61850/server/model/dynamic_model.c index 790c9be3..f9fb87af 100644 --- a/src/iec61850/server/model/dynamic_model.c +++ b/src/iec61850/server/model/dynamic_model.c @@ -611,21 +611,24 @@ DataObject_create(const char* name, ModelNode* parent, int arrayElements) self->elementCount = arrayElements; self->arrayIndex = -1; - if (arrayElements > 0) { + if (arrayElements > 0) + { int i; - for (i = 0; i < arrayElements; i++) { + for (i = 0; i < arrayElements; i++) + { DataObject* arrayElement = (DataObject*) GLOBAL_MALLOC(sizeof(DataObject)); - if (self) { - self->name = NULL; - self->modelType = DataObjectModelType; - self->firstChild = NULL; - self->parent = parent; - self->sibling = NULL; + if (arrayElement) + { + arrayElement->name = NULL; + arrayElement->modelType = DataObjectModelType; + arrayElement->firstChild = NULL; + arrayElement->parent = parent; + arrayElement->sibling = NULL; - self->elementCount = 0; - self->arrayIndex = i; + arrayElement->elementCount = 0; + arrayElement->arrayIndex = i; DataObject_addChild(self, (ModelNode*) arrayElement); } diff --git a/src/iec61850/server/model/model.c b/src/iec61850/server/model/model.c index 375d62f9..b15cfdb8 100644 --- a/src/iec61850/server/model/model.c +++ b/src/iec61850/server/model/model.c @@ -760,12 +760,14 @@ ModelNode_getChildWithIdx(ModelNode* self, int idx) { ModelNode* foundElement = NULL; - if (self->modelType == DataObjectModelType || self->modelType == DataAttributeModelType) { + if (self->modelType == DataObjectModelType || self->modelType == DataAttributeModelType) + { ModelNode* nextNode = self->firstChild; int currentIdx = 0; - while (nextNode) { + while (nextNode) + { if (currentIdx == idx) { foundElement = nextNode; break;