1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

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 are fixed, leaving us with an
almost warning-free compilation in 64-bit platforms:

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:67: warning: cast from pointer to integer of different size
menu.c:112: warning: cast from pointer to integer of different size
switchmenu.c:452: warning: cast from pointer to integer of different size
window.c:140: warning: cast from pointer to integer of different size
window.c:2217: warning: cast to pointer from integer of different size
workspace.c:135: warning: cast to pointer from integer of different size
workspace.c:214: warning: cast to pointer from integer of different size
workspace.c:634: warning: cast to pointer from integer of different size
workspace.c:1330: warning: cast to pointer from integer of different size
workspace.c:1514: warning: cast to pointer from integer of different size
wfilepanel.c:135: warning: cast from pointer to integer of different size
wfilepanel.c:171: warning: cast from pointer to integer of different size
wfontpanel.c:499: warning: cast to pointer from integer of different size
wfontpanel.c:500: warning: cast to pointer from integer of different size
wfontpanel.c:505: warning: cast to pointer from integer of different size
wfontpanel.c:506: warning: cast to pointer from integer of different size
wfontpanel.c:776: warning: cast from pointer to integer of different size
wfontpanel.c:777: warning: cast from pointer to integer of different size
wfontpanel.c:877: warning: cast from pointer to integer of different size
wfontpanel.c:878: warning: cast from pointer to integer of different size
wpanel.c:363: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:90: warning: cast to pointer from integer of different size
puzzle.c:138: warning: cast from pointer to integer of different size
puzzle.c:225: warning: cast to pointer from integer of different size
wtableview.c:1031: warning: cast to pointer from integer of different size
wtableview.c:1067: warning: cast to pointer from integer of different size
wtableview.c:1069: warning: cast to pointer from integer of different size
wtableview.c:1074: warning: cast to pointer from integer of different size
wtabledelegates.c:234: warning: cast from pointer to integer of different size
wtabledelegates.c:250: warning: cast from pointer to integer of different size
wtabledelegates.c:265: warning: cast from pointer to integer of different size
wtabledelegates.c:287: warning: cast to pointer from integer of different size
wtabledelegates.c:351: warning: cast from pointer to integer of different size
wtabledelegates.c:372: warning: cast from pointer to integer of different size
wtabledelegates.c:393: warning: cast from pointer to integer of different size
wtabledelegates.c:410: warning: cast to pointer from integer of different size
test.c:44: warning: cast from pointer to integer of different size
test.c:47: warning: cast to pointer from integer of different size
test.c:55: warning: cast from pointer to integer of different size
test.c:58: warning: cast from pointer to integer of different size
This commit is contained in:
Carlos R. Mafra
2008-11-06 01:37:44 +01:00
parent 4339e446e4
commit 06f59b9928
15 changed files with 62 additions and 48 deletions

View File

@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <WINGs/WINGs.h>
#include <WINGs/WUtil.h>
@@ -39,7 +40,8 @@ void show(WMWidget *self, void *data)
void *d;
WMLabel *l = (WMLabel*)data;
d = WMGetHangedData(self);
sprintf(buf, "%i - 0x%x - 0%o", (int)d, (int)d, (int)d);
sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t)d, (int)(uintptr_t)d,
(int)(uintptr_t)d);
WMSetLabelText(l, buf);
}
@@ -87,7 +89,7 @@ main(int argc, char **argv)
sprintf(buf, "%c", c);
WMSetButtonText(lab, buf);
WMSetButtonAction(lab, show, pos);
WMHangData(lab, (void*)c);
WMHangData(lab, (void*)(uintptr_t)c);
if (c>0) {
WMGroupButtons(l0, lab);
} else {

View File

@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <WINGs/WINGs.h>
#include <stdint.h>
#define MAX_SIZE 10*10
@@ -135,7 +135,7 @@ void buttonClick(WMWidget *w, void *ptr)
{
char buffer[300];
if (SlideButton((int)ptr)) {
if (SlideButton((int)(uintptr_t)ptr)) {
MoveCount++;
if (CheckWin()) {
@@ -222,7 +222,7 @@ int main(int argc, char **argv)
Button[i] = WMCreateButton(win, WBTMomentaryLight);
WMSetWidgetBackgroundColor(Button[i], color);
WMReleaseColor(color);
WMSetButtonAction(Button[i], buttonClick, (void*)i);
WMSetButtonAction(Button[i], buttonClick, (void*)(uintptr_t)i);
WMResizeWidget(Button[i], WinSize/Size, WinSize/Size);
WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size));
sprintf(buf, "%i", i+1);

View File

@@ -2,6 +2,7 @@
#include <WINGs/WINGs.h>
#include <stdio.h>
#include <stdint.h>
#include "wtableview.h"
#include "wtabledelegates.h"
@@ -41,10 +42,10 @@ valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
col2[i] = 0;
}
}
if ((int)WMGetTableColumnId(column) == 1)
if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
return col1[row];
else
return (void*)col2[row];
return (void*)(uintptr_t)col2[row];
}
@@ -52,10 +53,10 @@ void
setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
void *data)
{
if ((int)WMGetTableColumnId(column) == 1)
if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
col1[row] = data;
else
col2[row] = (int)data;
col2[row] = (int)(uintptr_t)data;
}

View File

@@ -1,5 +1,5 @@
#include <stdint.h>
#include <WINGs/WINGsP.h>
#include "wtableview.h"
@@ -231,7 +231,7 @@ ESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
{
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
WMTableView *table = WMGetTableColumnTableView(column);
int i = (int)WMTableViewDataForCell(table, column, row);
int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
@@ -247,7 +247,7 @@ selectedESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
{
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
WMTableView *table = WMGetTableColumnTableView(column);
int i = (int)WMTableViewDataForCell(table, column, row);
int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
@@ -262,7 +262,7 @@ beginESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
{
EnumSelectorData *strdata = (EnumSelectorData*)self->data;
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
int data = (int)WMTableViewDataForCell(strdata->table, column, row);
int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
wassertr(data < strdata->count);
@@ -284,7 +284,7 @@ endESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
WMUnmapWidget(strdata->widget);
option = WMGetPopUpButtonSelectedItem(strdata->widget);
WMSetTableViewDataForCell(strdata->table, column, row, (void*)option);
WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)option);
}
@@ -348,7 +348,7 @@ BSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
{
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
WMTableView *table = WMGetTableColumnTableView(column);
int i = (int)WMTableViewDataForCell(table, column, row);
int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
WMScreen *scr = WMWidgetScreen(table);
if (i) {
@@ -369,7 +369,7 @@ selectedBSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
{
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
WMTableView *table = WMGetTableColumnTableView(column);
int i = (int)WMTableViewDataForCell(table, column, row);
int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
WMScreen *scr = WMWidgetScreen(table);
if (i) {
@@ -390,7 +390,7 @@ beginBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
{
BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
int data = (int)WMTableViewDataForCell(strdata->table, column, row);
int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
WMSetButtonSelected(strdata->widget, data);
WMMoveWidget(strdata->widget, rect.pos.x+1, rect.pos.y+1);
@@ -407,7 +407,7 @@ endBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
int value;
value = WMGetButtonSelected(strdata->widget);
WMSetTableViewDataForCell(strdata->table, column, row, (void*)value);
WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)value);
WMUnmapWidget(strdata->widget);
}

View File

@@ -2,6 +2,7 @@
#include <WINGs/WINGsP.h>
#include <X11/cursorfont.h>
#include <stdint.h>
#include "wtableview.h"
@@ -1028,7 +1029,7 @@ drawRow(WMTableView *table, int row, WMRect clipRect)
if (!column->delegate || !column->delegate->drawCell)
continue;
if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound)
(*column->delegate->drawSelectedCell)(column->delegate, column, row, d);
else
(*column->delegate->drawCell)(column->delegate, column, row, d);
@@ -1064,14 +1065,14 @@ setRowSelected(WMTableView *table, unsigned row, Bool flag)
{
int repaint = 0;
if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound) {
if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound) {
if (!flag) {
WMRemoveFromArray(table->selectedRows, (void*)row);
WMRemoveFromArray(table->selectedRows, (void*)(uintptr_t)row);
repaint = 1;
}
} else {
if (flag) {
WMAddToArray(table->selectedRows, (void*)row);
WMAddToArray(table->selectedRows, (void*)(uintptr_t)row);
repaint = 1;
}
}

View File

@@ -8,6 +8,7 @@
#include <dirent.h>
#include <limits.h>
#include <errno.h>
#include <stdint.h>
#ifndef PATH_MAX
#define PATH_MAX 1024
@@ -132,7 +133,7 @@ textChangedObserver(void *observerData, WMNotification *notification)
return;
text = WMGetTextFieldText(panel->fileField);
textEvent = (int)WMGetNotificationClientData(notification);
textEvent = (int)(uintptr_t)WMGetNotificationClientData(notification);
if (panel->flags.autoCompletion && textEvent!=WMDeleteTextEvent)
i = closestListItem(list, text, False);
@@ -168,7 +169,7 @@ textEditedObserver(void *observerData, WMNotification *notification)
{
W_FilePanel *panel = (W_FilePanel*)observerData;
if ((int)WMGetNotificationClientData(notification)==WMReturnTextMovement) {
if ((int)(uintptr_t)WMGetNotificationClientData(notification)==WMReturnTextMovement) {
WMPerformButtonClick(panel->okButton);
}
}

View File

@@ -8,6 +8,7 @@
#include <ctype.h>
#include <string.h>
#include <stdint.h>
#include <X11/Xft/Xft.h>
#include <fontconfig/fontconfig.h>
@@ -496,14 +497,14 @@ addSizeToTypeface(Typeface *face, int size)
for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) {
size = scalableFontSizes[j];
if (!WMCountInArray(face->sizes, (void*)size)) {
WMAddToArray(face->sizes, (void*)size);
if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) {
WMAddToArray(face->sizes, (void*)(uintptr_t)size);
}
}
WMSortArray(face->sizes, compare_int);
} else {
if (!WMCountInArray(face->sizes, (void*)size)) {
WMAddToArray(face->sizes, (void*)size);
if (!WMCountInArray(face->sizes, (void*)(uintptr_t)size)) {
WMAddToArray(face->sizes, (void*)(uintptr_t)size);
WMSortArray(face->sizes, compare_int);
}
}
@@ -773,8 +774,8 @@ typefaceClick(WMWidget *w, void *data)
WMClearList(panel->sizLs);
WM_ITERATE_ARRAY(face->sizes, size, i) {
if ((int)size != 0) {
sprintf(buffer, "%i", (int)size);
if ((int)(uintptr_t)size != 0) {
sprintf(buffer, "%i", (int)(uintptr_t)size);
WMAddListItem(panel->sizLs, buffer);
}
@@ -874,8 +875,8 @@ setFontPanelFontName(FontPanel *panel, char *family, char *style, double size)
WM_ITERATE_ARRAY(face->sizes, vsize, i) {
char buffer[32];
if ((int)vsize != 0) {
sprintf(buffer, "%i", (int)vsize);
if ((int)(uintptr_t)vsize != 0) {
sprintf(buffer, "%i", (int)(uintptr_t)vsize);
WMAddListItem(panel->sizLs, buffer);
}

View File

@@ -3,6 +3,7 @@
#include "WINGsP.h"
#include <X11/keysym.h>
#include <stdint.h>
@@ -360,7 +361,7 @@ endedEditingObserver(void *observerData, WMNotification *notification)
{
WMInputPanel *panel = (WMInputPanel*)observerData;
switch ((int)WMGetNotificationClientData(notification)) {
switch ((int)(uintptr_t)WMGetNotificationClientData(notification)) {
case WMReturnTextMovement:
if (panel->defBtn)
WMPerformButtonClick(panel->defBtn);

View File

@@ -24,6 +24,7 @@
#include <WINGs/WINGsP.h>
#include <WINGs/WUtil.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <ctype.h>
@@ -969,7 +970,7 @@ textEndedEditing(struct WMTextFieldDelegate *self, WMNotification *notif)
if (!menu->flags.isEditing)
return;
reason = (int)WMGetNotificationClientData(notif);
reason = (int)(uintptr_t)WMGetNotificationClientData(notif);
switch (reason) {
case WMEscapeTextMovement:

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {
}

View File

@@ -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) {

View File

@@ -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);
}
}