Bug 21204

Summary: bit_ffc and bit_ffs macros in bitstring.h test 1 byte too many.
Product: Base System Reporter: bob
Component: miscAssignee: dwmalone
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description bob 2000-09-11 16:50:01 UTC
The bit_ffc and bit_ffs macros both contain a for loop where they check
for their loop ctr variable (_byte) for <_ to the end value (_stopbyte).
Unfortunately, _stopbyte is preloaded to the number of bytes in the
bit string, not the last valid index value.  Consequently these macros
both process one too many bytes.

Fix: Here is a patch that I installed that works for me:
How-To-Repeat: Set all of the bits in the string and execute bit_ffc.  You will observe
that it returns the index of _stopbyte (which is beyond the string).
You can also try this with an all clear bitstring and use bit_ffs.
I haven't actually tried this, since I discovered the bug when using 
bit_ffc, but the loop conditions are identical in it so the bug no
doubt exists there as well.
Comment 1 dwmalone freebsd_committer freebsd_triage 2000-10-02 22:18:08 UTC
Responsible Changed
From-To: freebsd-bugs->dwmalone

I've looked at the patch and it seems correct. Anyone want to review it for 
me?
Comment 2 dwmalone freebsd_committer freebsd_triage 2000-10-30 11:24:33 UTC
State Changed
From-To: open->closed

Improved bitstring macros now in -current and -stable.