changeset 4560:9745c72fc2eb draft

DHCP6: Assert auto sla is only 32-bits It already is due to the use of fls32 above, but this assertion makes clang static analyser happy.
author Roy Marples <roy@marples.name>
date Mon, 22 Jul 2019 12:44:20 +0100
parents c9da6ac27892
children 0c069664f375
files src/dhcp6.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp6.c	Mon Jul 22 11:49:54 2019 +0100
+++ b/src/dhcp6.c	Mon Jul 22 12:44:20 2019 +0100
@@ -583,10 +583,14 @@
 
 #define BIT(n) (1UL << (n))
 #define BIT_MASK(len) (BIT(len) - 1)
-		if (ia->sla_max == 0)
+		if (ia->sla_max == 0) {
 			/* Work out the real sla_max from our bits used */
-			ia->sla_max = (uint32_t)BIT_MASK(asla.prefix_len -
-			    prefix->prefix_len);
+			bits = asla.prefix_len - prefix->prefix_len;
+			/* Make static analysis happy.
+			 * Bits cannot be bigger than 32 thanks to fls32. */
+			assert(bits <= 32);
+			ia->sla_max = (uint32_t)BIT_MASK(bits);
+		}
 	}
 
 	if (ipv6_userprefix(&prefix->prefix, prefix->prefix_len,