Skip to content

Commit

Permalink
Add missing checks to fmi3{Get|Set}Binary (#601)
Browse files Browse the repository at this point in the history
fixes #595
  • Loading branch information
t-sommer authored Oct 6, 2024
1 parent 7f8d2bb commit 6b2a24b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/fmi3Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ do { \
#define GET_VARIABLES(T) \
BEGIN_FUNCTION(Get ## T); \
if (nValueReferences == 0) goto TERMINATE; \
else ASSERT_NOT_NULL(valueReferences); \
ASSERT_NOT_NULL(valueReferences); \
if (nValues > 0) ASSERT_NOT_NULL(values); \
if (S->isDirtyValues) { \
CALL(calculateValues(S)); \
Expand Down Expand Up @@ -568,6 +568,21 @@ fmi3Status fmi3GetBinary(fmi3Instance instance,

BEGIN_FUNCTION(GetBinary);

if (nValueReferences == 0) {
goto TERMINATE;
} else {
ASSERT_NOT_NULL(valueReferences);
}

if (nValues > 0) {
ASSERT_NOT_NULL(values);
}

if (S->isDirtyValues) {
CALL(calculateValues(S));
S->isDirtyValues = false;
}

size_t index = 0;

for (size_t i = 0; i < nValueReferences; i++) {
Expand Down Expand Up @@ -695,12 +710,27 @@ fmi3Status fmi3SetBinary(fmi3Instance instance,

BEGIN_FUNCTION(SetBinary);

if (nValueReferences == 0) {
goto TERMINATE;
}

ASSERT_NOT_NULL(valueReferences);

size_t index = 0;

for (size_t i = 0; i < nValueReferences; i++) {
CALL(setBinary(S, (ValueReference)valueReferences[i], valueSizes, (const char* const*)values, nValues, &index));
}

if (nValueReferences > 0) {
S->isDirtyValues = true;
}

if (index != nValues) {
logError(S, "Expected nValues = %zu but was %zu.", index, nValues); \
CALL(Error);
}

END_FUNCTION();
}

Expand Down

0 comments on commit 6b2a24b

Please sign in to comment.