GNOME Bugzilla – Bug 742566
Bitfield structure members used for booleans
Last modified: 2015-02-01 22:32:38 UTC
This is a general toolkit-wide problem that I am unsure how to go about reporting right. Consider, as an example, the function gdk_window_set_event_compression. Its semantics looks obvious from the code, but it is not. s_e_c(w,FALSE) turns compression off; s_e_c(w,TRUE) turns it on. Easy. But: s_e_c(w,2) turns it OFF. The assignment will overflow the single-bit structure member and assign 0. This kind of thing obviously doesn't happen with a constant 2, but it can reasonably happen with, say, flag tests. Solution here: !! But how does one find all the cases of this? void gdk_window_set_event_compression (GdkWindow *window, gboolean event_compression) { g_return_if_fail (GDK_IS_WINDOW (window)); window->event_compression = event_compression; }
I don't think this is a super-pressing problem. If the api asks for a boolean, don't pass 2... That being said, we do use constructs like enabled = enabled != FALSE; in many boolean setters anyway.