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 141080 - Patch to remove multiple warnings in gdk/x11/gdkdnd-x11.c
Patch to remove multiple warnings in gdk/x11/gdkdnd-x11.c
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: X11
2.4.x
Other Linux
: Normal normal
: Small fix
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-04-25 16:38 UTC by Chris Sherlock
Modified: 2005-08-15 01:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (4.75 KB, patch)
2004-04-25 16:40 UTC, Chris Sherlock
none Details | Review

Description Chris Sherlock 2004-04-25 16:38:08 UTC
This is a tricky one. I was getting the following warnings:

gdkdnd-x11.c: In function `motif_read_target_table':
gdkdnd-x11.c:920: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c: In function `motif_check_dest':
gdkdnd-x11.c:1270: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c: In function `motif_read_initiator_info':
gdkdnd-x11.c:1464: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c: In function `xdnd_check_dest':
gdkdnd-x11.c:2384: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c:2404: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c: In function `xdnd_read_actions':
gdkdnd-x11.c:2451: warning: dereferencing type-punned pointer will break
strict-aliasing rules
gdkdnd-x11.c: In function `xdnd_enter_filter':

What I've found is the following:

      MotifTargetTableHeader *header = NULL;
      .
      .
      .
      XGetWindowProperty (display_x11->xdisplay,
                          display_x11->motif_drag_window,
                          motif_drag_targets_atom,
                          0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
                          motif_drag_targets_atom,
                          &type, &format, &nitems, &bytes_after,
                          (guchar **)&header);

is breaks gcc's C99 strict aliasing rules. To get around this, you need to
convert a guchar** to a MotifTargetTableHeader*. The only way I can see that is
valid is to create a guchar**, use this in parameter 12 of XGetWindowProperty,
cast this to a temporary gpointer, and then cast the temporary gpointer to an
XGetWindowProperty* variable. 

So the previous fragment will look like:

      MotifTargetTableHeader *header = NULL;
      .
      .
      .
      guchar **pheader;
      gpointer temp_header;
                                                                               
                                                                   .
      .
      .
      XGetWindowProperty (display_x11->xdisplay,
                          display_x11->motif_drag_window,
                          motif_drag_targets_atom,
                          0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
                          motif_drag_targets_atom,
                          &type, &format, &nitems, &bytes_after,
                          pheader);

      temp_header = (gpointer) &pheader;
      header = (MotifTargetTableHeader*) &temp_header;

Very much a hack job, I feel (in fact I say as much in a comment in the diff).
However, it does remove the strict-aliasing warnings in gcc.
Comment 1 Chris Sherlock 2004-04-25 16:40:03 UTC
Created attachment 27079 [details] [review]
Proposed patch

Incidently, this patch also removed some other warnings I was getting as I
compiled the code.
Comment 2 Owen Taylor 2004-04-28 02:25:55 UTC
There is some real doubt whether we want to cater to
GCC's annoying paranoia/lack-of-understanding here at all, but if
you did want to fix up this warning, the correct way to do it
is to simply:

 guchar* data;

 XGetWindowProperty (..., &data, ...)
 header = (MotifTargetTableTable *)data;

Comment 3 Owen Taylor 2005-01-07 15:20:53 UTC
I got annoyed when working something else and fixed this in CVS a
while ago.

Tue Nov 16 19:26:30 2004  Owen Taylor  <otaylor@redhat.com>

        * gdk/x11/gdkdnd-x11.c (_gdk_drag_get_protocol_for_display):
        Squash strict aliasing warnings.