Project

General

Profile

Actions

Bug #2057

closed

another bit_nsearch fix

Added by useche over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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
++ 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_ */
Actions #1

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.

Actions

Also available in: Atom PDF