From 40c5abb0d02e4b558e6f1bbb94c754828b2e8bb5 Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Wed, 15 Jul 2026 05:39:46 +0800 Subject: [PATCH] Fix -Wsign-conversion/-Wconversion warnings in depth_for_size and buddy_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 #63). Fixes #152 --- buddy_alloc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buddy_alloc.h b/buddy_alloc.h index f906fbc..4ff6094 100644 --- a/buddy_alloc.h +++ b/buddy_alloc.h @@ -1118,8 +1118,8 @@ static size_t depth_for_size(struct buddy *buddy, size_t requested_size) { effective_memory_size = buddy_effective_memory_size(buddy); p2_of_requested_size = ceiling_power_of_two(requested_size); - depth = count_trailing_zeroes(effective_memory_size) + 1 - - count_trailing_zeroes(p2_of_requested_size); + depth = (size_t)(count_trailing_zeroes(effective_memory_size) + 1 + - count_trailing_zeroes(p2_of_requested_size)); return depth; } @@ -1995,7 +1995,7 @@ static unsigned char buddy_tree_fragmentation(struct buddy_tree *t) { quality_percent = (integer_square_root(quality) << fractional_bits) / total_free_size; quality_percent *= quality_percent; quality_percent >>= fractional_bits; - return fractional_mask - (quality_percent & fractional_mask); + return (unsigned char)(fractional_mask - (quality_percent & fractional_mask)); } #ifdef BUDDY_EXPERIMENTAL_CHANGE_TRACKING