Re: [gtk-list] bug in glib.h / g_bit_nth_msf



On Sun, 15 Nov 1998, Andreas Bombe wrote:

> I found an off-by-one error in glib.h in the g_bit_nth_msf macro.  It sets
> nth_bit to 33 in case it's called with nth_bit < 0.  This value is reduced by
> one immediately thereafter, but 1<<32 is off limits for a 32 bit variable.

yep, it should immeditedly set it to 32 and then test for 1 << 31, it is
not a real error though, since with 33 the first test for 1 << 32 will always
fail and then 1 << 31 is tested after that.

> Also nth_bit shouldn't be checked for <0 but <1.

nope, g_bit_nth_lsf and g_bit_nth_msf are supposed to test and report the
least/most significant bit within a specified mask, starting at a specified
bit position with -1 indicating the leftmost/rightmost bit respectively.
so the possible return values range from 0 to 31 for succesfull tests, or
-1 for a failing test.
this way the functions can be used in constructs like (from gmessage.c):

gint i;

for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
  {
    /* stuff to be done for each bit which is set in log_level, with
     * i indicating its shift-count, starting with the most significant bit.
     */
  }
  

> 
> Andreas E. Bombe <andreas.bombe@munich.netsurf.de>
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]