Skip to content

Commit

Permalink
fix undefined behavior with certain left-shift count values
Browse files Browse the repository at this point in the history
Change-Id: I1b71de28312a56a3b1d27fcfaf0a7b71d5777e6c
  • Loading branch information
StanChesnutt committed Dec 16, 2010
1 parent e88a1b9 commit 36f93f0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libnetutils/ifc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 36f93f0

Please sign in to comment.