From 9c75b925d72f796408c5cfbfe21e09360ed10b9a Mon Sep 17 00:00:00 2001 From: Venkatesh Srinivas Date: Thu, 5 May 2011 01:28:59 -0700 Subject: [PATCH] bitstring.h -- Correct errors in bit_nsearch. * bit_nsearch returned 0, not the correct -1, for a size 0 request. * bit_nsearch returned 0, not the correct -1, for requests larger than the bitvector. * bit_nsearch didn't find a zero cluster if it was the last one in a vector. Submitted-by: Luis Useche Closes bug: 2057 --- include/bitstring.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/bitstring.h b/include/bitstring.h index 975f8b6de2..6c47b4b26b 100644 --- a/include/bitstring.h +++ b/include/bitstring.h @@ -172,34 +172,28 @@ typedef unsigned char bitstr_t; int _nbits = (nbits); \ int *_value = (value); \ int _len = (len); \ - int _bit, _bit0; \ + int _bit, _bit0 = -1; \ int _tmplen = _len; \ int _match = 0; \ *(_value) = -1; \ - for (_bit = 0; _bit < _nbits; _bit++) { \ + for (_bit = 0; _bit < _nbits && _tmplen > 0; _bit++) { \ if (_match == 0) { \ if (bit_test((_name), _bit) == 0) { \ _match = 1; \ _tmplen--; \ _bit0 = _bit; \ - } else { \ - continue; \ } \ } else { \ - if (_tmplen > 0) { \ - if (bit_test((_name), _bit) == 0) { \ - _tmplen--; \ - } else { \ - _match = 0; \ - _tmplen = _len; \ - continue; \ - } \ + if (bit_test((_name), _bit) == 0) { \ + _tmplen--; \ } else { \ - *(_value) = _bit0; \ - break; \ + _match = 0; \ + _tmplen = _len; \ } \ } \ } \ + if (_tmplen == 0) \ + *(_value) = _bit0; \ } while (0) #endif /* !_BITSTRING_H_ */ -- 2.41.0