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

A couple of -Wconversion fixes #58

Merged
merged 5 commits into from Mar 26, 2019
Merged

Conversation

vadz
Copy link
Collaborator

@vadz vadz commented Mar 24, 2019

No description provided.

@vslavik
Copy link
Owner

vslavik commented Mar 26, 2019

Looks good to me...

This fixes a few -Wconversion gcc warnings and, more importantly,
actually ensures that there are no integer overflows in the code which
might result in real problems.

Add checked_int_cast() helper which is used to check for such overflows
in all the places where gcc flags of them and throws an exception
instead of using a wrong (wrapped) value if it happens.
This fixes another -Wconversion warning given by g++ 4.8 but,
surprisingly, not later versions for some reason.
This is unnecessary and results in -Wsign-conversion gcc warning.
There are no more warnings of this kind in the current sources, ensure
that new ones are not introduced later by making them immediately
visible (and fatal) in CI builds.
Unlike gcc, clang enables -Wsign-conversion when -Wconversion is
specified for C++ code too (gcc does it for C only), and enabling
-Wconversion uncovered a couple of instances where this warning was
given.

Fix them and enable -Wsign-conversion for gcc too for consistency and
fix a bunch more of very similar warnings given by gcc which were,
surprisingly, not given by clang, by using checked_size_t_cast() helper
similar to checked_int_cast() added in the previous commit.
@vadz
Copy link
Collaborator Author

vadz commented Mar 26, 2019

OK, I'm going to merge this one too now that it actually passes the CI builds (somehow I didn't get any of the errors in the previous build with my local g++...).

@vadz vadz merged commit de7ed43 into vslavik:master Mar 26, 2019
@vadz vadz deleted the fix-w-conversion branch March 26, 2019 18:20
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.

None yet

2 participants