another bit_nsearch fix

看板DFBSD_submit作者時間14年前 (2011/05/17 08:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
Hi Guys, This is yet another fix to bit_nsearch in bitstring.h. This patch solves 2 problems on bit_nsearch: 1. When the cluster of 0's found is in the last bits of the string, the algorithm was not returning the cluster as result. 2. When a cluster of size 0 was requested, it was returning a wrong answer. Below is the patch. Thanks, Luis. --- old_bitstring.h 2011-04-27 12:02:37.351084009 -0400 +++ bitstring.h 2011-04-27 11:53:38.721084004 -0400 @@ -172,34 +178,28 @@ 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_ */
文章代碼(AID): #1DqRh2Xf (DFBSD_submit)