From owner-freebsd-hackers@freebsd.org Tue Jul 11 08:19:08 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 434E7D98C9E for ; Tue, 11 Jul 2017 08:19:08 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 039B16625F; Tue, 11 Jul 2017 08:19:07 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dUqNn-0007Id-6G; Tue, 11 Jul 2017 10:18:59 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dUqNm-0003q2-S5; Tue, 11 Jul 2017 10:18:58 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id EBBCC2A004F; Tue, 11 Jul 2017 10:19:13 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id prqLA_sXUKiY; Tue, 11 Jul 2017 10:19:13 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id AF3C12A1677; Tue, 11 Jul 2017 10:19:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3yyoCnq11kAr; Tue, 11 Jul 2017 10:19:13 +0200 (CEST) Received: from linux-diu0.suse (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 8FE6E2A004F; Tue, 11 Jul 2017 10:19:13 +0200 (CEST) From: Sebastian Huber To: freebsd-hackers@freebsd.org Cc: kib@freebsd.org Subject: [PATCH] bitset(9): Fix BIT_FLS() Date: Tue, 11 Jul 2017 10:18:57 +0200 Message-Id: <20170711081857.8059-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.12.3 X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.99.2/23551/Mon Jul 10 14:11:07 2017) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jul 2017 08:19:08 -0000 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