[10148] in The GTK GIMP ToolKit mailing list archive
[gtk-list] Re: bug in glib.h / g_bit_nth_msf
daemon@ATHENA.MIT.EDU (Tim Janik)
Mon Nov 16 02:45:16 1998
From: Tim Janik <timj@gtk.org>
Date: Mon, 16 Nov 1998 07:47:40 +0100 (CET)
To: Andreas Bombe <andreas.bombe@munich.netsurf.de>
cc: Gtk+ MList <gtk-list@redhat.com>
In-Reply-To: <19981115033859.B2834@storm.local>
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com
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
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null