After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 742566 - Bitfield structure members used for booleans
Bitfield structure members used for booleans
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
3.15.x
Other All
: Normal minor
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-01-08 02:54 UTC by Morten Welinder
Modified: 2015-02-01 22:32 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Morten Welinder 2015-01-08 02:54:24 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;
}
Comment 1 Matthias Clasen 2015-01-09 03:33:18 UTC
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.