From: Thomas Graf Date: Thu, 31 Jan 2013 09:59:10 +0000 (+0100) Subject: Fix mask calculation in nl_addr_cmp_prefix() X-Git-Tag: libnl3_2_22rc1~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87458abbd03b0928b9d2ddd84b7bcb07892450d0;p=libnl Fix mask calculation in nl_addr_cmp_prefix() Signed-off-by: Malte Langermann Signed-off-by: Thomas Graf --- diff --git a/lib/addr.c b/lib/addr.c index 806664b..9089be8 100644 --- a/lib/addr.c +++ b/lib/addr.c @@ -525,8 +525,8 @@ int nl_addr_cmp_prefix(struct nl_addr *a, struct nl_addr *b) int bytes = len / 8; d = memcmp(a->a_addr, b->a_addr, bytes); - if (d == 0) { - int mask = (1UL << (len % 8)) - 1UL; + if (d == 0 && (len % 8) != 0) { + int mask = (0xFF00 >> (len % 8)) & 0xFF; d = (a->a_addr[bytes] & mask) - (b->a_addr[bytes] & mask);