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

[PATCH] wmaker: Fix compiler warnings about pointer <--> integer conversion



Subject: [PATCH] wmaker: Fix compiler warnings about pointer <--> integer conversion

There may be issues with running applications in 64-bit mode when
they were written with tacit assumptions about 32-bit platforms.
For example,

    * Assuming that a pointer can be cast back and forth to an integer

The reason is that the size of the integer and pointer may be different.
See the description of "[PATCH] Warn when casting a pointer (constant)
to an integer of different size." in the gcc mailing list

http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01881.html

where it was also suggested the use of casts to uintptr_t. This is
what this patch does.

As a result the following warnings (from src/) are fixed:

defaults.c: In function 'wReadDefaults':
defaults.c:1446: warning: cast to pointer from integer of different size
defaults.c:1457: warning: cast to pointer from integer of different size
defaults.c:1471: warning: cast to pointer from integer of different size
defaults.c:1486: warning: cast to pointer from integer of different size

icon.c: In function 'appearanceObserver':
icon.c:67: warning: cast from pointer to integer of different size

menu.c: In function 'appearanceObserver':
menu.c:112: warning: cast from pointer to integer of different size

switchmenu.c: In function 'wsobserver':
switchmenu.c:452: warning: cast from pointer to integer of different size

window.c: In function 'appearanceObserver':
window.c:140: warning: cast from pointer to integer of different size
window.c: In function 'wWindowChangeWorkspace':
window.c:2217: warning: cast to pointer from integer of different size

workspace.c: In function 'wWorkspaceNew':
workspace.c:135: warning: cast to pointer from integer of different size
workspace.c: In function 'wWorkspaceDelete':
workspace.c:214: warning: cast to pointer from integer of different size
workspace.c: In function 'wWorkspaceForceChange':
workspace.c:634: warning: cast to pointer from integer of different size
workspace.c: In function 'wWorkspaceRename':
workspace.c:1330: warning: cast to pointer from integer of different size
workspace.c: In function 'wWorkspaceRestoreState':
workspace.c:1514: warning: cast to pointer from integer of different size
---
 src/defaults.c   |    9 +++++----
 src/icon.c       |    3 ++-
 src/menu.c       |    3 ++-
 src/switchmenu.c |    3 ++-
 src/window.c     |    5 +++--
 src/workspace.c  |   11 ++++++-----
 6 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/defaults.c b/src/defaults.c
index c07ad37..7bc18e0 100644
--- a/src/defaults.c
+++ b/src/defaults.c
@@ -24,6 +24,7 @@
 #include "wconfig.h"
 
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -1443,7 +1444,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict)
             foo |= WColorSettings;
         if (foo)
             WMPostNotificationName(WNMenuTitleAppearanceSettingsChanged, NULL,
-                                   (void*)foo);
+                                   (void*)(uintptr_t)foo);
 
         foo = 0;
         if (needs_refresh & REFRESH_MENU_TEXTURE)
@@ -1454,7 +1455,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict)
             foo |= WColorSettings;
         if (foo)
             WMPostNotificationName(WNMenuAppearanceSettingsChanged, NULL,
-                                   (void*)foo);
+                                   (void*)(uintptr_t)foo);
 
         foo = 0;
         if (needs_refresh & REFRESH_WINDOW_FONT) {
@@ -1468,7 +1469,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict)
         }
         if (foo)
             WMPostNotificationName(WNWindowAppearanceSettingsChanged, NULL,
-                                   (void*)foo);
+                                   (void*)(uintptr_t)foo);
 
         if (!(needs_refresh & REFRESH_ICON_TILE)) {
             foo = 0;
@@ -1483,7 +1484,7 @@ wReadDefaults(WScreen *scr, WMPropList *new_dict)
             }
             if (foo)
                 WMPostNotificationName(WNIconAppearanceSettingsChanged, NULL,
-                                       (void*)foo);
+                                       (void*)(uintptr_t)foo);
         }
         if (needs_refresh & REFRESH_ICON_TILE)
             WMPostNotificationName(WNIconTileSettingsChanged, NULL,  NULL);
diff --git a/src/icon.c b/src/icon.c
index 19a918c..3ff44ac 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -26,6 +26,7 @@
 #include <X11/Xutil.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <string.h>
 #include <unistd.h>
 #include <ctype.h>
@@ -64,7 +65,7 @@ static void
 appearanceObserver(void *self, WMNotification *notif)
 {
     WIcon *icon = (WIcon*)self;
-    int flags = (int)WMGetNotificationClientData(notif);
+    int flags = (int)(uintptr_t)WMGetNotificationClientData(notif);
 
     if (flags & WTextureSettings) {
         icon->force_paint = 1;
diff --git a/src/menu.c b/src/menu.c
index 04b05a1..c6c1837 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <ctype.h>
 #if 0
@@ -109,7 +110,7 @@ static void
 appearanceObserver(void *self, WMNotification *notif)
 {
     WMenu *menu = (WMenu*)self;
-    int flags = (int)WMGetNotificationClientData(notif);
+    int flags = (int)(uintptr_t)WMGetNotificationClientData(notif);
 
     if (!menu->flags.realized)
         return;
diff --git a/src/switchmenu.c b/src/switchmenu.c
index 544652b..0db6e71 100644
--- a/src/switchmenu.c
+++ b/src/switchmenu.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -449,7 +450,7 @@ wsobserver(void *self, WMNotification *notif)
     void *data = WMGetNotificationClientData(notif);
 
     if (strcmp(name, WMNWorkspaceNameChanged) == 0) {
-        UpdateSwitchMenuWorkspace(scr, (int)data);
+        UpdateSwitchMenuWorkspace(scr, (int)(uintptr_t)data);
     } else if (strcmp(name, WMNWorkspaceChanged) == 0) {
 
     }
diff --git a/src/window.c b/src/window.c
index 0b6a39a..6cefe6c 100644
--- a/src/window.c
+++ b/src/window.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
 
 /* For getting mouse wheel mappings from WINGs */
 #include <WINGs/WINGsP.h>
@@ -137,7 +138,7 @@ static void
 appearanceObserver(void *self, WMNotification *notif)
 {
     WWindow *wwin = (WWindow*)self;
-    int flags = (int)WMGetNotificationClientData(notif);
+    int flags = (int)(uintptr_t)WMGetNotificationClientData(notif);
 
     if (!wwin->frame || (!wwin->frame->titlebar && !wwin->frame->resizebar))
         return;
@@ -2214,7 +2215,7 @@ wWindowChangeWorkspace(WWindow *wwin, int workspace)
 
         wwin->frame->workspace = workspace;
 
-        WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)oldWorkspace);
+        WMPostNotificationName(WMNChangedWorkspace, wwin, (void*)(uintptr_t)oldWorkspace);
     }
 
     if (unmap) {
diff --git a/src/workspace.c b/src/workspace.c
index fd27b83..3c72710 100644
--- a/src/workspace.c
+++ b/src/workspace.c
@@ -29,6 +29,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <string.h>
@@ -132,7 +133,7 @@ wWorkspaceNew(WScreen *scr)
 #endif
 
         WMPostNotificationName(WMNWorkspaceCreated, scr,
-                               (void*)(scr->workspace_count-1));
+                               (void*)(uintptr_t)(scr->workspace_count-1));
         XFlush(dpy);
 
         return scr->workspace_count-1;
@@ -211,7 +212,7 @@ wWorkspaceDelete(WScreen *scr, int workspace)
 #endif
 
     WMPostNotificationName(WMNWorkspaceDestroyed, scr,
-                           (void*)(scr->workspace_count-1));
+                           (void*)(uintptr_t)(scr->workspace_count-1));
 
     if (scr->current_workspace >= scr->workspace_count)
         wWorkspaceChange(scr, scr->workspace_count-1);
@@ -631,7 +632,7 @@ wWorkspaceForceChange(WScreen *scr, int workspace)
 
     showWorkspaceName(scr, workspace);
 
-    WMPostNotificationName(WMNWorkspaceChanged, scr, (void*)workspace);
+    WMPostNotificationName(WMNWorkspaceChanged, scr, (void*)(uintptr_t)workspace);
 
     /*   XSync(dpy, False); */
 }
@@ -1327,7 +1328,7 @@ wWorkspaceRename(WScreen *scr, int workspace, char *name)
     if (scr->clip_icon)
         wClipIconPaint(scr->clip_icon);
 
-    WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)workspace);
+    WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)(uintptr_t)workspace);
 }
 
 
@@ -1511,7 +1512,7 @@ wWorkspaceRestoreState(WScreen *scr)
             }
         }
 
-        WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)i);
+        WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)(uintptr_t)i);
     }
 }
 


-- 
To unsubscribe, send mail to wmaker-dev-unsubscribe@lists.windowmaker.info.