Skip to content

Commit

Permalink
handle empty Output dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored and robbr48 committed Nov 4, 2024
1 parent 5e66a51 commit 1cae8b7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/fmi4c_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,22 @@ bool parseModelStructureElement(fmi3ModelStructureElement *output, ezxml_t *elem
output->numberOfDependencies = 0;
const char* dependencies = NULL;
if(parseStringAttributeEzXml(*element, "dependencies", &dependencies)) {

if(dependencies == NULL || dependencies[0] == '\0') {
//If dependencies is empty, no need to parse further
return true;
}

//Duplicate the dependencies string to make it mutable
char* nonConstDependencies = _strdup(dependencies);
free((char*)dependencies);

//Count number of dependencies
if(nonConstDependencies != NULL) {
output->numberOfDependencies = 1;
}
else {
return true;
if (nonConstDependencies == NULL) {
return false; //strdup failed, handle as an error
}

//Count the number of dependencies based on space-delimited tokens
output->numberOfDependencies = 1;
for(int i=0; nonConstDependencies[i]; ++i) {
if(nonConstDependencies[i] == ' ') {
++output->numberOfDependencies;
Expand Down

0 comments on commit 1cae8b7

Please sign in to comment.