-
Notifications
You must be signed in to change notification settings - Fork 62
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
Properly handle stream errors when reading math objects #180
Properly handle stream errors when reading math objects #180
Conversation
Many classes use temporary variables in operator>> to read data from the stream. However, if stream operations fail, the variables will not be modified, and the temporary variables, which are POD data types, remain uninitialized. Often, but not always, this happens to be zero, which is probably why this bug remained undetected for so long. This is ultimately the reason why the sdformat Utils_TEST sometimes fails with an empty pose string: the empty string causes the uninitialized values to propagate to the Pose, while the unit test clearly expects the default value. This PR modifies the >> operators such that an invalid input will not change the underlying object at all. Signed-off-by: Timo Röhling <timo@gaussglocke.de>
a721b52
to
fa8d692
Compare
Codecov Report
@@ Coverage Diff @@
## ign-math6 #180 +/- ##
==========================================
Coverage 99.19% 99.19%
==========================================
Files 61 61
Lines 5978 5981 +3
==========================================
+ Hits 5930 5933 +3
Misses 48 48
Continue to review full report at Codecov.
|
Great catch @roehling ! I may be wrong, but I guess this is a problem that would have been detected by running the tests suite under Valgrind or the MemorySanitizer. In my experience the systematic use of Valgring is easier (even if slower during the tests), as it does not require to rebuild the library but only to add few lines of CMake in the macro that adds tests, see for example https://github.com/dic-iit/bipedal-locomotion-framework/blob/e43cc1827fa1e2062f117fc37f1bf986cf6b5fc3/cmake/AddBipedalLocomotionUnitTest.cmake#L19 and https://github.com/dic-iit/bipedal-locomotion-framework/blob/e43cc1827fa1e2062f117fc37f1bf986cf6b5fc3/cmake/AddBipedalLocomotionUnitTest.cmake#L76 . |
Valgrind is really good (I actually used it to discover that the underlying problem was an uninitialized value), but tends to eat lots of RAM for its bookkeeping. |
That is exactly the reason why in https://github.com/dic-iit/bipedal-locomotion-framework/blob/e43cc1827fa1e2062f117fc37f1bf986cf6b5fc3/cmake/AddBipedalLocomotionUnitTest.cmake#L19 we have a separate option to enable the (additional) Valgrind tests. Normal developers just pass |
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 for the fix!
it looks like this fixes gazebosim/sdformat#407 |
Many classes use temporary variables in operator>> to read data from the
stream. However, if stream operations fail, the variables will not be
modified, and the temporary variables, which are POD data types, remain
uninitialized. Often, but not always, this happens to be zero, which is
probably why this bug remained undetected for so long.
This is ultimately the reason why the sdformat Utils_TEST sometimes
fails with an empty pose string: the empty string causes the
uninitialized values to propagate to the Pose, while the unit test
clearly expects the default value.
This PR modifies the >> operators such that an invalid input will not
change the underlying object at all.