fix undefined behavior with certain left-shift count values

Change-Id: I1b71de28312a56a3b1d27fcfaf0a7b71d5777e6c
This commit is contained in:
Stan Chesnutt 2010-12-16 10:59:48 -08:00
parent e88a1b9e3d
commit 36f93f0120
1 changed files with 5 additions and 0 deletions

View File

@ -224,6 +224,11 @@ in_addr_t get_ipv4_netmask(int prefix_length)
{
in_addr_t mask = 0;
// C99 (6.5.7): shifts of 32 bits have undefined results
if (prefix_length == 0) {
return 0;
}
mask = ~mask << (32 - prefix_length);
mask = htonl(mask);