From 96695efe835951c667acb6017d2c169e0320574c Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 2 Feb 2016 22:52:40 +0000 Subject: [PATCH] Use fls64 instead of ffs64 because we're interested in how many bits a number is so it fits. --- configure | 20 ++++++++++---------- dhcp6.c | 9 ++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 24cac8f0..541e091f 100755 --- a/configure +++ b/configure @@ -985,23 +985,23 @@ if [ "$BE64ENC" = no ]; then echo "#include \"compat/endian.h\"" >>$CONFIG_H fi -if [ -z "$FFS64" ]; then - printf "Testing for ffs64 ... " - cat <_ffs64.c +if [ -z "$FLS64" ]; then + printf "Testing for fls64 ... " + cat <_fls64.c #include int main(void) { - return (int)ffs64(1337); + return (int)fls64(1337); } EOF - if $XCC _ffs64.c -o _ffs64 2>&3; then - FFS64=yes + if $XCC _fls64.c -o _fls64 2>&3; then + FLS64=yes else - FFS64=no + FLS64=no fi - echo "$FFS64" - rm -f _ffs64.c _ffs64 + echo "$FLS64" + rm -f _fls64.c _fls64 fi -if [ "$FFS64" = yes ]; then +if [ "$FLS64" = yes ]; then echo "#define HAVE_SYS_BITOPS_H" >>$CONFIG_H fi diff --git a/dhcp6.c b/dhcp6.c index 0e6b958b..bd6eb52c 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -424,13 +424,13 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp, sla_max = 0; TAILQ_FOREACH(ifi, ifp->ctx->ifaces, next) { - if (ifi != ifp && ifi->index > sla_max) + if (ifi->index > sla_max) sla_max = ifi->index; } } else sla_max = ia->sla_max; - bits = ffs32(sla_max); + bits = fls32(sla_max); if (prefix->prefix_len + bits > UINT8_MAX) asla.prefix_len = UINT8_MAX; @@ -443,10 +443,9 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp, asla.prefix_len = 64; else asla.prefix_len = (uint8_t)ROUNDUP8(asla.prefix_len); - } -#define BIT(n) (1l << (n)) +#define BIT(n) (1UL << (n)) #define BIT_MASK(len) (BIT(len) - 1) if (ia->sla_max == 0) /* Work out the real sla_max from our bits used */ @@ -2355,7 +2354,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix, sla, ia)) == -1) return NULL; - if (ffs64(sla->suffix) > 128 - pfxlen) { + if (fls64(sla->suffix) > 128 - pfxlen) { logger(ifp->ctx, LOG_ERR, "%s: suffix %" PRIu64 " + prefix_len %d > 128", ifp->name, sla->suffix, pfxlen);