From 286d83260216e8e53db701eed5c785aae1c716bf Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 29 Jun 2016 01:36:31 +0200 Subject: Use internal temp variable for swap macros. Make swaps/swapl type safe (introducing wrong_size check at build time). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While working on this changeset, various spots got discovered where swapl or swaps was used on a wrong type, where byte swapping calls had been forgotten or done on the wrong variable. This backport at least includes changes from the following X.org commits, listed in non-chronological order: commit 2c7c520cfe0df30f4bc3adba59d9c62582823bf8 Author: Matt Turner Date: Thu Aug 4 15:35:41 2011 -0400 Use internal temp variable for swap macros Also, fix whitespace, mainly around swaps(&rep.sequenceNumber) Reviewed-by: Peter Harris Signed-off-by: Matt Turner commit 9edcae78c46286baff42e74bfe26f6ae4d00fe01 Author: Matt Turner Date: Wed Sep 21 17:14:16 2011 -0400 Use correct swap{l,s} (or none at all for CARD8) Swapping the wrong size was never caught because swap{l,s} are macros. It's clear in the case of Xext/xres.c, that the author believed client_major/minor to be CARD16 from looking at the code in the first hunk. v2: dmx.c fixes from Keith. Reviewed-by: Peter Harris Signed-off-by: Matt Turner commit dab064fa5e0b1f5c67222562ad5367005832cba1 Author: Andrea Canciani Date: Tue Nov 2 20:10:32 2010 +0100 render: Fix byteswapping of gradient stops The function swapStops repeatedly swaps the color components as CARD16, but incorrectly steps over them as if they were CARD32. This causes half of the stops not to be swapped at all and some unrelated data be swapped instead. Signed-off-by: Andrea Canciani Reviewed-by: Soren Sandmann Reviewed-by: Julien Cristau Signed-off-by: Keith Packard commit 54770c980cd2b91a8377f975a58ed69def5cfa42 Author: Matt Turner Date: Tue Aug 16 16:59:07 2011 -0400 Cast char* buffers to swap functions Reviewed-by: Peter Harris Signed-off-by: Matt Turner commit 6844bd2e63490870bab3c469eec6030354ef2865 Author: Alan Coopersmith Date: Wed Jan 9 19:52:00 2008 -0800 More Xv extension byte swapping fixes commit e46f6ddeccd082b2d507a1e8b57ea30e6b0a2c83 Author: Michel Dänzer Date: Wed Jan 16 14:24:22 2008 +0100 Yet another Xv extension byte swapping fix. --- nx-X11/programs/Xserver/dix/swaprep.c | 401 ++++++++++++++-------------------- 1 file changed, 161 insertions(+), 240 deletions(-) (limited to 'nx-X11/programs/Xserver/dix/swaprep.c') diff --git a/nx-X11/programs/Xserver/dix/swaprep.c b/nx-X11/programs/Xserver/dix/swaprep.c index 31c823b3a..e5c722f31 100644 --- a/nx-X11/programs/Xserver/dix/swaprep.c +++ b/nx-X11/programs/Xserver/dix/swaprep.c @@ -78,14 +78,13 @@ void Swap32Write(ClientPtr pClient, int size, register CARD32 *pbuf) { register int i; - register char n; size >>= 2; for(i = 0; i < size; i++) /* brackets are mandatory here, because "swapl" macro expands to several statements */ { - swapl(&pbuf[i], n); + swapl(&pbuf[i]); } (void)WriteToClient(pClient, size << 2, (char *) pbuf); } @@ -191,9 +190,7 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) void SGenericReply(ClientPtr pClient, int size, xGenericReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); + swaps(&pRep->sequenceNumber); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -202,67 +199,57 @@ void SGetWindowAttributesReply(ClientPtr pClient, int size, xGetWindowAttributesReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->visualID, n); - swaps(&pRep->class, n); - swapl(&pRep->backingBitPlanes, n); - swapl(&pRep->backingPixel, n); - swapl(&pRep->colormap, n); - swapl(&pRep->allEventMasks, n); - swapl(&pRep->yourEventMask, n); - swaps(&pRep->doNotPropagateMask, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->visualID); + swaps(&pRep->class); + swapl(&pRep->backingBitPlanes); + swapl(&pRep->backingPixel); + swapl(&pRep->colormap); + swapl(&pRep->allEventMasks); + swapl(&pRep->yourEventMask); + swaps(&pRep->doNotPropagateMask); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->root, n); - swaps(&pRep->x, n); - swaps(&pRep->y, n); - swaps(&pRep->width, n); - swaps(&pRep->height, n); - swaps(&pRep->borderWidth, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->root); + swaps(&pRep->x); + swaps(&pRep->y); + swaps(&pRep->width); + swaps(&pRep->height); + swaps(&pRep->borderWidth); (void)WriteToClient(pClient, size, (char *) pRep); } void SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->root, n); - swapl(&pRep->parent, n); - swaps(&pRep->nChildren, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->root); + swapl(&pRep->parent); + swaps(&pRep->nChildren); (void)WriteToClient(pClient, size, (char *) pRep); } void SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->atom, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->atom); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nameLength, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nameLength); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -270,24 +257,20 @@ SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply *pRep) void SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->propertyType, n); - swapl(&pRep->bytesAfter, n); - swapl(&pRep->nItems, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->propertyType); + swapl(&pRep->bytesAfter); + swapl(&pRep->nItems); (void)WriteToClient(pClient, size, (char *) pRep); } void SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nProperties, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nProperties); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -295,10 +278,8 @@ void SGetSelectionOwnerReply(ClientPtr pClient, int size, xGetSelectionOwnerReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->owner, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->owner); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -306,27 +287,23 @@ SGetSelectionOwnerReply(ClientPtr pClient, int size, void SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->root, n); - swapl(&pRep->child, n); - swaps(&pRep->rootX, n); - swaps(&pRep->rootY, n); - swaps(&pRep->winX, n); - swaps(&pRep->winY, n); - swaps(&pRep->mask, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->root); + swapl(&pRep->child); + swaps(&pRep->rootX); + swaps(&pRep->rootY); + swaps(&pRep->winX); + swaps(&pRep->winY); + swaps(&pRep->mask); (void)WriteToClient(pClient, size, (char *) pRep); } void SwapTimecoord(xTimecoord* pCoord) { - register char n; - - swapl(&pCoord->time, n); - swaps(&pCoord->x, n); - swaps(&pCoord->y, n); + swapl(&pCoord->time); + swaps(&pCoord->x); + swaps(&pCoord->y); } void @@ -348,33 +325,27 @@ SwapTimeCoordWrite(ClientPtr pClient, int size, xTimecoord *pRep) void SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->nEvents, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->nEvents); (void)WriteToClient(pClient, size, (char *) pRep); } void STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->child, n); - swaps(&pRep->dstX, n); - swaps(&pRep->dstY, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->child); + swaps(&pRep->dstX); + swaps(&pRep->dstY); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->focus, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->focus); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -382,10 +353,8 @@ SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply *pRep) void SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -393,30 +362,26 @@ static void SwapCharInfo(xCharInfo *pInfo) { - register char n; - - swaps(&pInfo->leftSideBearing, n); - swaps(&pInfo->rightSideBearing, n); - swaps(&pInfo->characterWidth, n); - swaps(&pInfo->ascent, n); - swaps(&pInfo->descent, n); - swaps(&pInfo->attributes, n); + swaps(&pInfo->leftSideBearing); + swaps(&pInfo->rightSideBearing); + swaps(&pInfo->characterWidth); + swaps(&pInfo->ascent); + swaps(&pInfo->descent); + swaps(&pInfo->attributes); } static void SwapFontInfo(xQueryFontReply *pr) { - register char n; - - swaps(&pr->minCharOrByte2, n); - swaps(&pr->maxCharOrByte2, n); - swaps(&pr->defaultChar, n); - swaps(&pr->nFontProps, n); - swaps(&pr->fontAscent, n); - swaps(&pr->fontDescent, n); + swaps(&pr->minCharOrByte2); + swaps(&pr->maxCharOrByte2); + swaps(&pr->defaultChar); + swaps(&pr->nFontProps); + swaps(&pr->fontAscent); + swaps(&pr->fontDescent); SwapCharInfo( &pr->minBounds); SwapCharInfo( &pr->maxBounds); - swapl(&pr->nCharInfos, n); + swapl(&pr->nCharInfos); } static @@ -427,10 +392,9 @@ SwapFont(xQueryFontReply *pr, Bool hasGlyphs) xCharInfo * pxci; unsigned nchars, nprops; char *pby; - register char n; - swaps(&pr->sequenceNumber, n); - swapl(&pr->length, n); + swaps(&pr->sequenceNumber); + swapl(&pr->length); nchars = pr->nCharInfos; nprops = pr->nFontProps; SwapFontInfo(pr); @@ -439,9 +403,9 @@ SwapFont(xQueryFontReply *pr, Bool hasGlyphs) * they are always 2 4 byte values */ for(i = 0; i < nprops; i++) { - swapl(pby, n); + swapl((int *)pby); pby += 4; - swapl(pby, n); + swapl((int *)pby); pby += 4; } if (hasGlyphs) @@ -462,27 +426,23 @@ SQueryFontReply(ClientPtr pClient, int size, xQueryFontReply *pRep) void SQueryTextExtentsReply(ClientPtr pClient, int size, xQueryTextExtentsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->fontAscent, n); - swaps(&pRep->fontDescent, n); - swaps(&pRep->overallAscent, n); - swaps(&pRep->overallDescent, n); - swapl(&pRep->overallWidth, n); - swapl(&pRep->overallLeft, n); - swapl(&pRep->overallRight, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->fontAscent); + swaps(&pRep->fontDescent); + swaps(&pRep->overallAscent); + swaps(&pRep->overallDescent); + swapl(&pRep->overallWidth); + swapl(&pRep->overallLeft); + swapl(&pRep->overallRight); (void)WriteToClient(pClient, size, (char *) pRep); } void SListFontsReply(ClientPtr pClient, int size, xListFontsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nFonts, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nFonts); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -497,22 +457,18 @@ SListFontsWithInfoReply(ClientPtr pClient, int size, void SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nPaths, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nPaths); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetImageReply(ClientPtr pClient, int size, xGetImageReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->visual, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->visual); (void)WriteToClient(pClient, size, (char *) pRep); /* Fortunately, image doesn't need swapping */ } @@ -521,11 +477,9 @@ void SListInstalledColormapsReply(ClientPtr pClient, int size, xListInstalledColormapsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nColormaps, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nColormaps); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -535,41 +489,35 @@ SAllocColorReply(pClient, size, pRep) int size; xAllocColorReply *pRep; { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->red, n); - swaps(&pRep->green, n); - swaps(&pRep->blue, n); - swapl(&pRep->pixel, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->red); + swaps(&pRep->green); + swaps(&pRep->blue); + swapl(&pRep->pixel); (void)WriteToClient(pClient, size, (char *) pRep); } void SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->pixel, n); - swaps(&pRep->exactRed, n); - swaps(&pRep->exactGreen, n); - swaps(&pRep->exactBlue, n); - swaps(&pRep->screenRed, n); - swaps(&pRep->screenGreen, n); - swaps(&pRep->screenBlue, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->pixel); + swaps(&pRep->exactRed); + swaps(&pRep->exactGreen); + swaps(&pRep->exactBlue); + swaps(&pRep->screenRed); + swaps(&pRep->screenGreen); + swaps(&pRep->screenBlue); (void)WriteToClient(pClient, size, (char *) pRep); } void SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nPixels, n); - swaps(&pRep->nMasks, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nPixels); + swaps(&pRep->nMasks); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -577,25 +525,21 @@ SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply *pRep) void SAllocColorPlanesReply(ClientPtr pClient, int size, xAllocColorPlanesReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nPixels, n); - swapl(&pRep->redMask, n); - swapl(&pRep->greenMask, n); - swapl(&pRep->blueMask, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nPixels); + swapl(&pRep->redMask); + swapl(&pRep->greenMask); + swapl(&pRep->blueMask); (void)WriteToClient(pClient, size, (char *) pRep); } void SwapRGB(xrgb *prgb) { - register char n; - - swaps(&prgb->red, n); - swaps(&prgb->green, n); - swaps(&prgb->blue, n); + swaps(&prgb->red); + swaps(&prgb->green); + swaps(&prgb->blue); } void @@ -617,47 +561,39 @@ SQColorsExtend(ClientPtr pClient, int size, xrgb *prgb) void SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply* pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nColors, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nColors); (void)WriteToClient(pClient, size, (char *) pRep); } void SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->exactRed, n); - swaps(&pRep->exactGreen, n); - swaps(&pRep->exactBlue, n); - swaps(&pRep->screenRed, n); - swaps(&pRep->screenGreen, n); - swaps(&pRep->screenBlue, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->exactRed); + swaps(&pRep->exactGreen); + swaps(&pRep->exactBlue); + swaps(&pRep->screenRed); + swaps(&pRep->screenGreen); + swaps(&pRep->screenBlue); (void)WriteToClient(pClient, size, (char *) pRep); } void SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->width, n); - swaps(&pRep->height, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->width); + swaps(&pRep->height); (void)WriteToClient(pClient, size, (char *) pRep); } void SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -665,10 +601,8 @@ void SGetKeyboardMappingReply(ClientPtr pClient, int size, xGetKeyboardMappingReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -676,10 +610,8 @@ void SGetPointerMappingReply(ClientPtr pClient, int size, xGetPointerMappingReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -687,46 +619,38 @@ void SGetModifierMappingReply(ClientPtr pClient, int size, xGetModifierMappingReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetKeyboardControlReply(ClientPtr pClient, int size, xGetKeyboardControlReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swapl(&pRep->ledMask, n); - swaps(&pRep->bellPitch, n); - swaps(&pRep->bellDuration, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swapl(&pRep->ledMask); + swaps(&pRep->bellPitch); + swaps(&pRep->bellDuration); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetPointerControlReply(ClientPtr pClient, int size, xGetPointerControlReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->accelNumerator, n); - swaps(&pRep->accelDenominator, n); - swaps(&pRep->threshold, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->accelNumerator); + swaps(&pRep->accelDenominator); + swaps(&pRep->threshold); (void)WriteToClient(pClient, size, (char *) pRep); } void SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swaps(&pRep->timeout, n); - swaps(&pRep->interval, n); + swaps(&pRep->sequenceNumber); + swaps(&pRep->timeout); + swaps(&pRep->interval); (void)WriteToClient(pClient, size, (char *) pRep); } @@ -738,8 +662,7 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf) while (bufT < endbuf) { xHostEntry *host = (xHostEntry *) bufT; int len = host->length; - register char n; - swaps (&host->length, n); + swaps (&host->length); bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2); } (void)WriteToClient (pClient, size, buf); @@ -748,11 +671,9 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf) void SListHostsReply(ClientPtr pClient, int size, xListHostsReply *pRep) { - register char n; - - swaps(&pRep->sequenceNumber, n); - swapl(&pRep->length, n); - swaps(&pRep->nHosts, n); + swaps(&pRep->sequenceNumber); + swapl(&pRep->length); + swaps(&pRep->nHosts); (void)WriteToClient(pClient, size, (char *) pRep); } -- cgit v1.2.3