Skip to content

Conversation

DavidPL1
Copy link

This change fixes a case in simulate.cc where std::memcpy could be invoked with a nullptr as the destination pointer. While the size argument would be zero in these cases, passing a null pointer to memcpy is still undefined behavior according to the C++ standard.

The updated logic ensures that memcpy is only called when both the destination pointer is valid and the number of bytes to copy is nonzero. This prevents potential undefined behavior and improves robustness.

Though it is very unlikely that anyone would load a model with nbody=0, njnt=0, and/or nq=0, I've still added guards for the respective memcpy calls, additionally to the much more realistic neq=0 and nu=0 ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant