From: Michael Tremer Date: Fri, 22 Mar 2024 14:42:30 +0000 (+0000) Subject: network: Fix handling bit length on merge X-Git-Tag: 0.9.18~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d7d3d6b635222f5a07c207859d9da554ddfd6c1;p=location%2Flibloc.git 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 --- 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;