From 8d7d3d6b635222f5a07c207859d9da554ddfd6c1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 22 Mar 2024 14:42:30 +0000 Subject: [PATCH] network: Fix handling bit length on merge The check was kind of useless because of incorrect values from the bit length function. Signed-off-by: Michael Tremer --- src/network.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/network.c b/src/network.c index 820413c..d658709 100644 --- a/src/network.c +++ b/src/network.c @@ -608,11 +608,15 @@ int loc_network_merge(struct loc_network** n, const unsigned int prefix = loc_network_prefix(n1); // How many bits do we need to represent this address? - const size_t bitlength = loc_address_bit_length(&n1->first_address) - 1; + const size_t bitlength = loc_address_bit_length(&n1->first_address); // We cannot shorten this any more - if (bitlength < prefix) + if (bitlength >= prefix) { + DEBUG(n1->ctx, "Cannot shorten this any further because we need at least %jd bits," + " but only have %d\n", bitlength, prefix); + return 0; + } // Increment the last address of the first network address = n1->last_address; -- 2.47.3