Date: Tue, 11 Jul 2017 10:18:57 +0200 From: Sebastian Huber <sebastian.huber@embedded-brains.de> To: freebsd-hackers@freebsd.org Cc: kib@freebsd.org Subject: [PATCH] bitset(9): Fix BIT_FLS() Message-ID: <20170711081857.8059-1-sebastian.huber@embedded-brains.de>
next in thread | raw e-mail | index | archive | help
Its embarrassing, but I got the loop wrong. The iteration index is
unsigned, so testing for larger than or equal to zero makes little
sense.
---
sys/sys/bitset.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h
index 1ed19531b3b..566d9448420 100644
--- a/sys/sys/bitset.h
+++ b/sys/sys/bitset.h
@@ -218,10 +218,10 @@
int __bit; \
\
__bit = 0; \
- for (__i = __bitset_words((_s)) - 1; __i >= 0; __i--) { \
- if ((p)->__bits[__i] != 0) { \
- __bit = flsl((p)->__bits[__i]); \
- __bit += __i * _BITSET_BITS; \
+ for (__i = __bitset_words((_s)); __i > 0; __i--) { \
+ if ((p)->__bits[__i - 1] != 0) { \
+ __bit = flsl((p)->__bits[__i - 1]); \
+ __bit += (__i - 1) * _BITSET_BITS; \
break; \
} \
} \
--
2.12.3
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170711081857.8059-1-sebastian.huber>
