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

Fix build warnings on Windows #390

Merged
merged 5 commits into from
Apr 2, 2022

Conversation

jacobperron
Copy link
Contributor

@jacobperron jacobperron commented Apr 1, 2022

We noticed these warnings when building orocos_kdl as part of ROS 2 CI, see https://ci.ros2.org/job/ci_windows/16708/msbuild

I've triggered a new Windows build with the changes in this PR: Build Status

These were caught as MSBuild warnings on Windows.
In most cases, acknowledge that the conversions may lose precision by doing a static cast.
In one case we change the type of an argument to be more accurate.

Signed-off-by: Jacob Perron <[email protected]>
Fixes a MSBuild warning on Windows.

Signed-off-by: Jacob Perron <[email protected]>
@@ -156,7 +156,7 @@ bool Tree::getChain(const std::string& chain_root, const std::string& chain_tip,
}

// add the segments from the common frame to the tip frame
for (int s=parents_chain_tip.size()-1; s>-1; s--){
for (int s=static_cast<int>(parents_chain_tip.size())-1; s>-1; s--){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not go for an unsigned int here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The condition for the loop is to check if s>-1, so it must be able to become negative.

Copy link
Collaborator

@MatthijsBurgh MatthijsBurgh Apr 1, 2022

Choose a reason for hiding this comment

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

And if we check for s>=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If s is an unsigned int it cannot be negative, so s-- will cause an integer overflow and this will become an infinite loop.

I've updated the code to use a reverse iterator, which I think makes it more readable (3324420).

@@ -61,7 +61,7 @@ class TreeIkSolverPos_Online: public TreeIkSolverPos {
* @return
*/

TreeIkSolverPos_Online(const double& nr_of_jnts,
TreeIkSolverPos_Online(const unsigned int& nr_of_jnts,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an API breaking change. This has been discussed in #384. So I think we should skip this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to avoid breaking API: d70e705

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why, but it looks like this change (d70e705) broke a test 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since most of the members we were initializing with this value where being overridden immediately in the constructor, I've just removed them from the initializer list (fc0dfd8). CI looks happy now.

orocos_kdl/src/utilities/error_stack.cxx Show resolved Hide resolved
Use static cast instead to avoid compiler warnings.

Signed-off-by: Jacob Perron <[email protected]>
They are set inside the constructor anyways.

Signed-off-by: Jacob Perron <[email protected]>
@jacobperron
Copy link
Contributor Author

I guess CI is flaky? Since the same change passed CI on my fork: https://github.com/jacobperron/orocos_kinematics_dynamics/runs/5796424695?check_suite_focus=true

@MatthijsBurgh
Copy link
Collaborator

I guess CI is flaky? Since the same change passed CI on my fork:

Yes, see #239

@MatthijsBurgh MatthijsBurgh merged commit de91a8e into orocos:master Apr 2, 2022
@jacobperron jacobperron deleted the fix_msbuild_warnings branch April 2, 2022 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants