Skip to content

Prevent segfault in PyKDL when asking for nonexisting segment of chain #228

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
11 changes: 9 additions & 2 deletions python_orocos_kdl/PyKDL/kinfam.sip
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,15 @@ public:

unsigned int getNrOfJoints()const;
unsigned int getNrOfSegments()const;

const Segment& getSegment(unsigned int nr)const /Factory/;

const Segment* getSegment(unsigned int nr)const /Factory/;
%MethodCode
if (a0 < 0 || a0 >= (unsigned int)sipCpp->getNrOfSegments()) {
PyErr_SetString(PyExc_IndexError, "Chain index out of range");
return 0;
}
sipRes = &(sipCpp->getSegment(a0));
Copy link
Member

Choose a reason for hiding this comment

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

Actually I am not sure if this is valid in SIP. The /Factory/ annotation indicates that the returned pointer is owned by Python, but actually the returned pointer must not be deleted independently. I wonder whether that annotation was actually correct even for the original version of the method.

Why did you change the return type from const Segment& to const Segment*?

Could anybody who is more proficient with SIP could jump in (@smits)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not mean to change the return type, that must have slipped in while I was testing, good catch.

%End

};

Expand Down