Work around implementation-dependent shift results
authorAlan T. DeKok <aland@freeradius.org>
Sat, 6 Mar 2010 11:13:54 +0000 (12:13 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 6 Mar 2010 11:18:40 +0000 (12:18 +0100)
uint32 foo = ~0;

foo <<= 32;

Q: what's foo?
A: undefined.

src/main/client.c

index 7df88d3..bd825db 100644 (file)
@@ -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;