Bug #2057
closedanother bit_nsearch fix
0%
Description
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 int _bit, _bit0; \
++ 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 = 1; \ for (_bit = 0; _bit < _nbits; _bit++) { \
int _tmplen = _len; \
int _match = 0; \
*(_value) = -1; \
+ 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_ */
Updated by vsrinivas over 13 years ago
Hi,
The fixes look to be correct and corrected the case where a request was larger
than the size of the bitstring (previously returned 0, not -1).
Fix committed in 9c75b925d72f796408c5cfbfe21e09360ed10b9a.