Skip to content

Commit

Permalink
Fix buffer size calculation in FMIAppendArrayToLogMessageBuffer()
Browse files Browse the repository at this point in the history
fixes #607
  • Loading branch information
t-sommer committed Oct 10, 2024
1 parent fda2fd1 commit 7157043
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/FMI.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ void FMIAppendArrayToLogMessageBuffer(FMIInstance* instance, const void* values,
continue;
}

if (length + sizeof(", ") < instance->logMessageBufferSize - instance->logMessageBufferPosition) {
const size_t requiredCharacters = length + sizeof(", ");

if (requiredCharacters < instance->logMessageBufferSize - instance->logMessageBufferPosition) {

instance->logMessageBufferPosition += length;
i++;

} else {

while (instance->logMessageBufferSize < instance->logMessageBufferPosition + length) {
while (instance->logMessageBufferSize < instance->logMessageBufferPosition + requiredCharacters) {
instance->logMessageBufferSize *= 2;
}

Expand Down

0 comments on commit 7157043

Please sign in to comment.