From: Denis Ovsienko Date: Fri, 16 Dec 2011 12:25:02 +0000 (+0400) Subject: lib: fix type-punning in ip_masklen() X-Git-Tag: frr-2.0-rc1~1918^2~25 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ce77002e908e8c9eeff780a6a34143af6758a17f;p=mirror%2Ffrr.git lib: fix type-punning in ip_masklen() ip_masklen() was likely to return incorrect results after being compiled with -fstrict-aliasing (-O2, -O3, -Os) --- diff --git a/lib/prefix.c b/lib/prefix.c index 19a5261093..23202b6235 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -2592,8 +2592,13 @@ masklen2ip (const int masklen, struct in_addr *netmask) u_char ip_masklen (struct in_addr netmask) { - u_int16_t * int16 = (u_int16_t *) &netmask.s_addr; - return map64kto17_nbo[int16[0]] + map64kto17_nbo[int16[1]]; + union + { + u_int32_t int32; + u_int16_t int16[2]; + } u; + u.int32 = netmask.s_addr; + return map64kto17_nbo[u.int16[0]] + map64kto17_nbo[u.int16[1]]; } /* Apply mask to IPv4 prefix (network byte order). */