-
Notifications
You must be signed in to change notification settings - Fork 2
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
librhsp getInterfacePacketID errors with segmentation fault. #133
Comments
update, I found the bug and was able to fix it(but probably in not a very good way lol) it turns out that ´rhsp_getInterfacePacketID´ does a transaction with the hub in the following order:
the bug:the code was failing in step 2 where it would check if there was an interface after querying.
First of all, in static const RhspModuleInterface* getInterfaceByName(const RhspModuleInterfaceListInternal* list,
const char* interfaceName)
{
for (size_t i = 0; i < list->numberOfInterfaces; i++)
{
if (strcmp(interfaceName, list->interfaces[i].name) == 0)
{
return &list->interfaces[i];
}
}
return NULL;
} take note that if the value of as the bug was still not fixed, I focused in understanding what was happening inside my first suspicion was that some string could be missing a null terminator, causing string operators to fail. thus, i added this line after the allocation of memory to intf_.name[interfaceNameLength-1] = 0; this also did not fix the issue, despite not breaking anything else. Therefore, the only other suspicion was that some garbage value was being stored in list->numberOfInterfaces resulting in a out of bounds memory acces in then I turned my focus to as I had already confirmed that the values set before the calling of this function were right, it was the main culprit for the segmentation fault. It turns out, that if so it was possible that so, to test if that was the case i added the following line after the allocation: ((RhspModuleInterfaceListInternal*) hub->interfaceList)->numberOfInterfaces = 0; And it worked!! |
Wow! Thank you for reporting and investigating this bug. We're not actively working on this library at the moment, but we do plan to return to it, and I'm sure we'll want to dive into this then. Moving |
My configuration:
What I'm trying to accomplish:
I'm trying to use a REV Expansion Hub to control a robot using ROS2 Humble by creating a custom ROS node in C++
I was able to connect to the hub and change the LED color, by using
rhsp_setModuleLedColor
by using the library tests as an example.The problem:
rhsp_setServoConfiguration
,rhsp_setMotorChannelMode
,rhsp_getEncoderPosition
and other commands give the same segmentation fault.it appears as any command containing
rhsp_getInterfacePacketID
creates the same behavior, apparently caused by thestrcmp
ingetInterfaceByName
debugging in GDB i get the following output:
Thanks in advance.
The text was updated successfully, but these errors were encountered: