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

Properly handle stream errors when reading math objects #180

Merged

Conversation

roehling
Copy link
Contributor

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.

@osrf-triage osrf-triage added this to Inbox in Core development Nov 26, 2020
@github-actions github-actions bot added 🏢 edifice Ignition Edifice 🏰 citadel Ignition Citadel 📜 blueprint Ignition Blueprint 🔮 dome Ignition Dome labels Nov 26, 2020
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>
@roehling roehling force-pushed the properly-handle-stream-errors branch from a721b52 to fa8d692 Compare November 26, 2020 13:55
@chapulina chapulina moved this from Inbox to In review in Core development Nov 30, 2020
scpeters added a commit to gazebo-tooling/release-tools that referenced this pull request Dec 2, 2020
@codecov
Copy link

codecov bot commented Dec 2, 2020

Codecov Report

Merging #180 (fa8d692) into ign-math6 (44a17a4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           ign-math6     #180   +/-   ##
==========================================
  Coverage      99.19%   99.19%           
==========================================
  Files             61       61           
  Lines           5978     5981    +3     
==========================================
+ Hits            5930     5933    +3     
  Misses            48       48           
Impacted Files Coverage Δ
include/ignition/math/Quaternion.hh 100.00% <ø> (ø)
include/ignition/math/Vector2.hh 100.00% <ø> (ø)
include/ignition/math/Vector3.hh 95.75% <ø> (ø)
include/ignition/math/Vector4.hh 94.44% <ø> (ø)
include/ignition/math/Color.hh 100.00% <100.00%> (ø)
include/ignition/math/Matrix3.hh 100.00% <100.00%> (ø)
include/ignition/math/Matrix4.hh 100.00% <100.00%> (ø)
include/ignition/math/Temperature.hh 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44a17a4...fa8d692. Read the comment docs.

@traversaro
Copy link
Contributor

traversaro commented Dec 2, 2020

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 .

@roehling
Copy link
Contributor Author

roehling commented Dec 2, 2020

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.

@traversaro
Copy link
Contributor

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 FRAMEWORK_COMPILE_tests=ON to get the usual non-Valgrind tests suite, then in CI (or if a developer wants to debug those) also FRAMEWORK_RUN_Valgrind_tests=ON is passed, that runs every test in the test suite also under Valgrind. In this way the work of the developers is not slowed down, until the CI catches a Memory-related problem in a test.

Copy link
Member

@scpeters scpeters left a 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!

@scpeters
Copy link
Member

scpeters commented Dec 2, 2020

it looks like this fixes gazebosim/sdformat#407

@scpeters scpeters merged commit 454e906 into gazebosim:ign-math6 Dec 2, 2020
Core development automation moved this from In review to Done Dec 2, 2020
@roehling roehling deleted the properly-handle-stream-errors branch December 2, 2020 09:23
@j-rivero j-rivero removed this from Done in Core development May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 blueprint Ignition Blueprint 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants