svn commit: r320893 - head/sys/sys

Konstantin Belousov kib at FreeBSD.org
Tue Jul 11 12:35:46 UTC 2017


Author: kib
Date: Tue Jul 11 12:35:44 2017
New Revision: 320893
URL: https://svnweb.freebsd.org/changeset/base/320893

Log:
  Fix BIT_FLS().
  
  The iteration index is unsigned, so testing for larger than or equal
  to zero makes little sense.
  
  Submitted by:	Sebastian Huber <sebastian.huber at embedded-brains.de>
  MFC after:	3 days

Modified:
  head/sys/sys/bitset.h

Modified: head/sys/sys/bitset.h
==============================================================================
--- head/sys/sys/bitset.h	Tue Jul 11 12:32:40 2017	(r320892)
+++ head/sys/sys/bitset.h	Tue Jul 11 12:35:44 2017	(r320893)
@@ -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;						\
 		}							\
 	}								\


More information about the svn-src-head mailing list