Skip to content

Commit

Permalink
Handle status != FMIOK in FMIReadModelDescription() (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer authored Sep 17, 2024
1 parent 44172e1 commit fc7bc48
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions fmusim/FMIModelDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit fc7bc48

Please sign in to comment.