-
Notifications
You must be signed in to change notification settings - Fork 104
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
CanBusMotionControl: corrected compilation warnings + potential bugs #761
Conversation
potential bugs: - setControlModeRaw() did not return false when it received an invalid control mode - in some c-string manipulation there was teh danger to write out of memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @marcoaccame 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for me. One thing that is worth noting is that probably that code did not use any std::string
or similar to avoid the use of dynamic memory allocation (that is a quite non-determistic operation and expensive, from the real time point of view) in a frequently invoked loop. If however you do not think this is a problem in this case, I am ok with the PR.
Good point @traversaro. The change to avoid the use of heap would be trivial: move the string out of the scope of the loop and reserve for it a reasonable chunk of memory. Any other operation on the string would not involve heap operations. std::string mystring;
mystring.reserve(512); |
Agreed 👍🏻 |
Hi @pattacini, I have just completed the change. |
Just waiting the CI and then merging. |
This fix landed in |
Purpose of the PR
This PR addresses what in issue #754 and fixes:
CanBusMotionControl::setControlModeRaw()
and similar methods did not return false when they receive an invalid control mode.Details of the changes
There are two changes:
CanBusMotionControl::from_modevocab_to_modeint()
used inside::setControlModeRaw()
to transform ayarp::conf::vocab32_t
into aicubCanProto_controlmode_t
.void CanBusMotionControl::run()
In the first case, the return value of
from_modevocab_to_modeint()
was compared vsVOCAB_CM_UNKNOWN
which was never returned because the function truncated its value (the warning was just saying that).Solved by returning
icubCanProto_controlmode_unknownError
instead.In the second case, some
sprintf()
did not have check vs writing out of memory in the case of particularly long strings. Solved by using astd::string
which gets the memory it needs.Tests
The changes are trivial and for this reason I did not test them on the robot.