From: Alan T. DeKok Date: Sat, 6 Mar 2010 11:13:54 +0000 (+0100) Subject: Work around implementation-dependent shift results X-Git-Url: http://www.project-moonshot.org/gitweb/?p=freeradius.git;a=commitdiff_plain;h=b3a5a8a4dcd123c5b1f926599c5a2cadb08eee11 Work around implementation-dependent shift results uint32 foo = ~0; foo <<= 32; Q: what's foo? A: undefined. --- diff --git a/src/main/client.c b/src/main/client.c index 7df88d3..bd825db 100644 --- a/src/main/client.c +++ b/src/main/client.c @@ -236,11 +236,16 @@ static int client_sane(RADCLIENT *client) uint32_t mask, *addr; addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr; - mask = ~ ((uint32_t) 0); - mask <<= (32 - (client->prefix & 0x1f)); - mask = htonl(mask); - switch ((client->prefix - 1) >> 5) { + if ((client->prefix & 0x1f) == 0) { + mask = 0; + } else { + mask = ~ ((uint32_t) 0); + mask <<= (32 - (client->prefix & 0x1f)); + mask = htonl(mask); + } + + switch (client->prefix >> 5) { case 0: addr[0] &= mask; mask = 0;