diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 8040419f728e..a2bb7cfc84d2 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -677,7 +677,7 @@ overflow_page(HTAB *hashp) bit = hashp->LAST_FREED & ((hashp->BSIZE << BYTE_SHIFT) - 1); j = bit / BITS_PER_MAP; - bit = bit & ~(BITS_PER_MAP - 1); + bit = rounddown2(bit, BITS_PER_MAP); } else { bit = 0; j = 0; diff --git a/lib/libc/net/ip6opt.c b/lib/libc/net/ip6opt.c index fda2cd4b8098..c2d292f2d966 100644 --- a/lib/libc/net/ip6opt.c +++ b/lib/libc/net/ip6opt.c @@ -130,8 +130,7 @@ inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ @@ -200,7 +199,7 @@ inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 1d37329a4d34..0023ecacdfbf 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -330,7 +330,7 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp) *errp = NO_RECOVERY; return NULL; } - if ((long)src & ~(sizeof(struct in_addr) - 1)) { + if (rounddown2((long)src, sizeof(struct in_addr))) { memcpy(&addrbuf, src, len); src = &addrbuf; } @@ -343,7 +343,8 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp) *errp = NO_RECOVERY; return NULL; } - if ((long)src & ~(sizeof(struct in6_addr) / 2 - 1)) { /*XXX*/ + if (rounddown2((long)src, sizeof(struct in6_addr) / 2)) { + /* XXX */ memcpy(&addrbuf, src, len); src = &addrbuf; }