Skip to content

Fix -Wsign-conversion/-Wconversion warnings in depth_for_size and buddy_tree_fragmentation - #153

Merged
spaskalev merged 1 commit into
spaskalev:mainfrom
94xhn:fix-conversion-warnings
Jul 15, 2026
Merged

Fix -Wsign-conversion/-Wconversion warnings in depth_for_size and buddy_tree_fragmentation#153
spaskalev merged 1 commit into
spaskalev:mainfrom
94xhn:fix-conversion-warnings

Conversation

@94xhn

@94xhn 94xhn commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #152

count_trailing_zeroes() returns unsigned char, so the arithmetic expression in depth_for_size() promotes to int and then implicitly narrows back to size_t on assignment to depth, triggering -Wsign-conversion. Similarly, in buddy_tree_fragmentation() the subtraction promotes fractional_mask to int and then narrows back to the unsigned char return 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.

…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
@spaskalev
spaskalev merged commit 53adbbb into spaskalev:main Jul 15, 2026
6 checks passed
@spaskalev

Copy link
Copy Markdown
Owner

@94xhn thank you for the contribution!

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.

Warnings when compiled with GCC

2 participants