> +/*
> + * fls: find last set bit.
> + *
> + * Returns the 1-based index of the most-significant bit in x. The MSB
> + * is bit number 32, the LSB is bit number 1. If x is zero, the result is
> + * undefined.
> + */
> +static inline int
> +fls(unsigned int x)
...
> + idx = fls((size - 1) >> ALLOC_MINBITS);
If size <= 8, fls((size - 1) >> ALLOC_MINBITS) is fls(0).
The result of fls(0) is undefined.
I think we have to never call fls(0) from AllocSetFreeIndex().
My proposal code:
if (size > (1 << ALLOC_MINBITS)) { idx = fls((size - 1) >> ALLOC_MINBITS); Assert(idx <
ALLOCSET_NUM_FREELISTS); }
Best regards,
---
Atsushi Ogawa