fix undefined behavior with certain left-shift count values
Change-Id: I1b71de28312a56a3b1d27fcfaf0a7b71d5777e6c
This commit is contained in:
parent
e88a1b9e3d
commit
36f93f0120
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue