summaryrefslogtreecommitdiffstats
path: root/libnetutils/ifc_utils.c
diff options
context:
space:
mode:
authorStan Chesnutt <chesnutt@google.com>2010-12-16 10:59:48 -0800
committerStan Chesnutt <chesnutt@google.com>2010-12-16 10:59:48 -0800
commit36f93f01201bbff4a411c73adfbaf08bd93b1ad2 (patch)
treeff262884f4b778bd4b8132d57954b706b43ab1b3 /libnetutils/ifc_utils.c
parente88a1b9e3d39376d2a33efff49229985fe8797e8 (diff)
downloadsystem_core-36f93f01201bbff4a411c73adfbaf08bd93b1ad2.zip
system_core-36f93f01201bbff4a411c73adfbaf08bd93b1ad2.tar.gz
system_core-36f93f01201bbff4a411c73adfbaf08bd93b1ad2.tar.bz2
fix undefined behavior with certain left-shift count values
Change-Id: I1b71de28312a56a3b1d27fcfaf0a7b71d5777e6c
Diffstat (limited to 'libnetutils/ifc_utils.c')
-rw-r--r--libnetutils/ifc_utils.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 0ca5fe6..95a144c 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -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);