Cast small-int values through intptr_t when passed as pointers

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@minilop.net>
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Jamey Sharp 2009-10-08 13:38:44 +11:00 committed by Daniel Stone
parent b680a89262
commit b0dd6be2c8
6 changed files with 14 additions and 12 deletions

View File

@ -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 */

View File

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

View File

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

View File

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

View File

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

View File

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