]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
network: Fix handling bit length on merge
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Mar 2024 14:42:30 +0000 (14:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Mar 2024 14:42:30 +0000 (14:42 +0000)
The check was kind of useless because of incorrect values from the bit
length function.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/network.c

index 820413cd6fb8fd0ff96817e450b6ea7faa483a7c..d658709f9dba3eae5be2ec38a0895327f2f45528 100644 (file)
@@ -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;