Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp] avoid null pointer deference in PhysicsConstraintTimeline #2694

Open
wants to merge 1 commit into
base: 4.2
Choose a base branch
from

Conversation

bendmorris
Copy link

Compiling spine-cpp with mingw and -Werror results in:

/home/ben/Dev/march/krit/spine-runtimes/spine-cpp/spine-cpp/src/spine/PhysicsConstraintTimeline.cpp:98:75: error: ‘this’ pointer is null [-Werror=nonnull]
   98 |                                 if (constraint->_active) constraint->reset();
      | 

This looks like a real issue as constraint is definitely null here. The intent seems pretty clear though so here's a quick fix - feel free to throw it away and fix it a different way.

@@ -95,6 +95,7 @@ void PhysicsConstraintResetTimeline::apply(Skeleton &skeleton, float lastTime, f
else {
Vector<PhysicsConstraint *> &physicsConstraints = skeleton.getPhysicsConstraints();
for (size_t i = 0; i < physicsConstraints.size(); i++) {
constraint = physicsConstraints[i];
if (constraint->_active) constraint->reset();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think you also want to if (constraint && constraint->_active)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a null check above either, or in other places where these are used. My assumption would be that getPhysicsConstraints returns a vector of non-null pointers so if you're within its size the check isn't necessary. If that's not the case happy to add the check.

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

Successfully merging this pull request may close these issues.

2 participants