Fix -Wsign-conversion/-Wconversion warnings in depth_for_size and buddy_tree_fragmentation - #153
Merged
Merged
Conversation
…dy_tree_fragmentation count_trailing_zeroes() returns unsigned char; the arithmetic in depth_for_size() promotes to int before implicitly narrowing back to size_t on assignment, triggering -Wsign-conversion. Similarly, the subtraction in buddy_tree_fragmentation() promotes to int before narrowing back to the unsigned char return type, triggering -Wconversion. Add explicit casts matching the project's existing conversion-warning cleanup style (see PR spaskalev#63). Fixes spaskalev#152
Owner
|
@94xhn thank you for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #152
count_trailing_zeroes()returnsunsigned char, so the arithmetic expression indepth_for_size()promotes tointand then implicitly narrows back tosize_ton assignment todepth, triggering-Wsign-conversion. Similarly, inbuddy_tree_fragmentation()the subtraction promotesfractional_masktointand then narrows back to theunsigned charreturn type, triggering-Wconversion.Added explicit casts at both sites, matching the style already used elsewhere in the codebase for this class of warning (see #63).
Verified with MinGW GCC 8.1.0 (
-std=c99 -Wall -Wextra -Wconversion -Wsign-conversion) that both warnings reproduce verbatim on the current header at the reported lines, and are gone after this change. Also ran the existing test suite before/after and diffed output — behavior is unchanged.