From fc7bc48bb464e0bd6dc6737c03ac18b93aec3563 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Tue, 17 Sep 2024 14:49:56 +0200 Subject: [PATCH] Handle status != FMIOK in FMIReadModelDescription() (#586) --- fmusim/FMIModelDescription.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/fmusim/FMIModelDescription.c b/fmusim/FMIModelDescription.c index 3031e928..0d4db2e4 100644 --- a/fmusim/FMIModelDescription.c +++ b/fmusim/FMIModelDescription.c @@ -228,15 +228,11 @@ static FMIModelDescription* readModelDescriptionFMI1(xmlNodePtr root) { xmlXPathFreeContext(xpathCtx); - if (nProblems > 0) { - FMIFreeModelDescription(modelDescription); - modelDescription = NULL; - } - TERMINATE: - if (status != FMIOK) { - FMIFree((void**)&modelDescription); + if (status != FMIOK || nProblems > 0) { + FMIFreeModelDescription(modelDescription); + modelDescription = NULL; } return modelDescription; @@ -655,14 +651,12 @@ static FMIModelDescription* readModelDescriptionFMI2(xmlNodePtr root) { nProblems += FMIValidateModelDescription(modelDescription); - if (nProblems > 0) { +TERMINATE: + + if (status != FMIOK || nProblems > 0) { FMIFreeModelDescription(modelDescription); modelDescription = NULL; } - -TERMINATE: - - // TODO return modelDescription; } @@ -1017,11 +1011,7 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) { const char* start = (char*)xmlGetProp(dimensionNode, (xmlChar*)"start"); const char* valueReference = (char*)xmlGetProp(dimensionNode, (xmlChar*)"valueReference"); - variable->dimensions = realloc(variable->dimensions, (variable->nDimensions + 1) * sizeof(FMIDimension)); - - if (!variable->dimensions) { - return NULL; - } + CALL(FMIRealloc(&variable->dimensions, (variable->nDimensions + 1) * sizeof(FMIDimension))); FMIDimension* dimension = &variable->dimensions[variable->nDimensions]; @@ -1084,15 +1074,13 @@ static FMIModelDescription* readModelDescriptionFMI3(xmlNodePtr root) { nProblems += FMIValidateModelDescription(modelDescription); - if (nProblems > 0) { +TERMINATE: + + if (status != FMIOK || nProblems > 0) { FMIFreeModelDescription(modelDescription); modelDescription = NULL; } -TERMINATE: - - // TODO - return modelDescription; }