[PATCH] Cast small-int values through intptr_t when they're passed as pointers.
Jamey Sharp
jamey at minilop.net
Fri Oct 2 13:42:50 PDT 2009
On 64-bit systems, int and pointers don't have the same size, so GCC gives
warnings about casts between int and pointer types. However, in the cases
covered by this patch, it's always a value that fits in int being stored
temporarily as a pointer and then converted back later, which is safe.
Casting through the pointer-sized integer type intptr_t convinces the
compiler that this is OK.
Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
Xext/xtest.c | 6 +++---
composite/compwindow.c | 4 ++--
dix/events.c | 4 ++--
glx/glxcmds.c | 2 +-
hw/xfree86/dri/dri.c | 8 +++++---
hw/xfree86/os-support/bus/linuxPci.c | 2 +-
6 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 6b0e9fd..5af2b5c 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -640,8 +640,8 @@ int AllocXTestDevice (ClientPtr client, char* name,
retval = AllocDevicePair( client, xtestname, ptr, keybd, CorePointerProc, CoreKeyboardProc, FALSE);
if ( retval == Success ){
- dixSetPrivate(&((*ptr)->devPrivates), XTestDevicePrivateKey, (void *)master_ptr->id);
- dixSetPrivate(&((*keybd)->devPrivates), XTestDevicePrivateKey, (void *)master_keybd->id);
+ dixSetPrivate(&((*ptr)->devPrivates), XTestDevicePrivateKey, (void *)(intptr_t)master_ptr->id);
+ dixSetPrivate(&((*keybd)->devPrivates), XTestDevicePrivateKey, (void *)(intptr_t)master_keybd->id);
XIChangeDeviceProperty(*ptr, XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
XA_INTEGER, 8, PropModeReplace, 1, &dummy,
@@ -677,7 +677,7 @@ IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master)
return is_XTest;
tmp = dixLookupPrivate(&dev->devPrivates, XTestDevicePrivateKey);
- mid = (int)tmp;
+ mid = (intptr_t)tmp;
/* deviceid 0 is reserved for XIAllDevices, non-zero mid means XTest
* device */
diff --git a/composite/compwindow.c b/composite/compwindow.c
index 4267a51..9bc43b0 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -99,7 +99,7 @@ static Bool
compRepaintBorder (ClientPtr pClient, pointer closure)
{
WindowPtr pWindow;
- int rc = dixLookupWindow(&pWindow, (XID)closure, pClient, DixWriteAccess);
+ int rc = dixLookupWindow(&pWindow, (XID)(intptr_t)closure, pClient, DixWriteAccess);
if (rc == Success) {
RegionRec exposed;
@@ -130,7 +130,7 @@ compSetPixmapVisitWindow (WindowPtr pWindow, pointer data)
SetBorderSize (pWindow);
if (HasBorder (pWindow))
QueueWorkProc (compRepaintBorder, serverClient,
- (pointer) pWindow->drawable.id);
+ (pointer)(intptr_t) pWindow->drawable.id);
return WT_WALKCHILDREN;
}
diff --git a/dix/events.c b/dix/events.c
index d60b8a5..14e3900 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1460,7 +1460,7 @@ static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex;
static void
DetachFromMaster(DeviceIntPtr dev)
{
- int id;
+ intptr_t id;
if (!dev->u.master)
return;
@@ -1482,7 +1482,7 @@ ReattachToOldMaster(DeviceIntPtr dev)
p = dixLookupPrivate(&dev->devPrivates, GrabPrivateKey);
- id = (int)p; /* silence gcc warnings */
+ id = (intptr_t) p; /* silence gcc warnings */
dixLookupDevice(&master, id, serverClient, DixUseAccess);
if (master)
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index ba4c123..eedab65 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2057,7 +2057,7 @@ int __glXDisp_BindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc)
if (ret == Success) {
if (barrier)
/* add source for cleanup when drawable is gone */
- AddResource(drawable, __glXSwapBarrierRes, (pointer)screen);
+ AddResource(drawable, __glXSwapBarrierRes, (pointer)(intptr_t)screen);
else
/* delete source */
FreeResourceByType(drawable, __glXSwapBarrierRes, FALSE);
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index faddfe6..0de9be6 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1277,7 +1277,7 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
/* track this in case the client dies */
AddResource(FakeClientID(client->index), DRIDrawablePrivResType,
- (pointer)pDrawable->id);
+ (pointer)(intptr_t)pDrawable->id);
if (pDRIDrawablePriv->hwDrawable) {
drmUpdateDrawableInfo(pDRIPriv->drmFD,
@@ -1348,7 +1348,7 @@ DRIDestroyDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable)
if (pDrawable->type == DRAWABLE_WINDOW) {
LookupClientResourceComplex(client, DRIDrawablePrivResType,
DRIDestroyDrawableCB,
- (pointer)pDrawable->id);
+ (pointer)(intptr_t)pDrawable->id);
}
else { /* pixmap (or for GLX 1.3, a PBuffer) */
/* NOT_DONE */
@@ -1364,7 +1364,9 @@ DRIDrawablePrivDelete(pointer pResource, XID id)
WindowPtr pWin;
int rc;
- id = (XID)pResource;
+ /* For DRIDrawablePrivResType, the XID is the client's fake ID. The
+ * important XID is the value in pResource. */
+ id = (XID)(intptr_t)pResource;
rc = dixLookupWindow(&pWin, id, serverClient, DixGetAttrAccess);
if (rc == Success) {
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index 920a149..289315e 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -445,7 +445,7 @@ xf86MapLegacyIO(struct pci_device *dev)
PCIIOC_MMAP_IS_IO);
}
else { /* legacy_io file exists, encode fd */
- DomainMmappedIO[domain] = (pointer)(fd << 24);
+ DomainMmappedIO[domain] = (pointer)(intptr_t)(fd << 24);
}
}
--
1.6.3.3
More information about the xorg-devel
mailing list