From 0f916ec3bcd7fd1b5b5ac1ff0a7b8548132ae00f Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 31 Oct 2018 23:44:52 +0000 Subject: [PATCH] Fix an error in common-prefix calculation --- nbase/nbase_addrset.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nbase/nbase_addrset.c b/nbase/nbase_addrset.c index 0ffb09214..3182a39b0 100644 --- a/nbase/nbase_addrset.c +++ b/nbase/nbase_addrset.c @@ -239,6 +239,10 @@ u32 common_mask(u32 a, u32 b) u8 r; // r will be lg(v) u32 t, tt; // temporaries u32 v = a ^ b; + if (v == 0) { + /* values are equal, all bits are the same */ + return 0xffffffff; + } if ((tt = v >> 16)) { @@ -250,7 +254,7 @@ u32 common_mask(u32 a, u32 b) } if (r + 1 >= 32) { /* shifting this many bits would overflow. Just return max mask */ - return 0xffffffff; + return 0; } else { return ~((1 << (r + 1)) - 1);