xserver: Branch 'master' - 18 commits
Peter Hutterer
whot at kemper.freedesktop.org
Mon Jul 13 17:42:09 PDT 2009
Xext/mbuf.c | 10 ++---
Xext/panoramiX.c | 4 +-
Xext/panoramiXprocs.c | 18 +++++-----
Xext/saver.c | 4 +-
Xext/security.c | 16 ++++-----
Xext/shape.c | 2 -
Xext/sync.c | 12 +++----
Xext/xf86bigfont.c | 2 -
Xext/xres.c | 4 +-
Xext/xselinux.c | 6 +--
Xext/xvdisp.c | 16 ++++-----
Xext/xvmc.c | 8 ++--
Xi/chgdctl.c | 6 +--
Xi/chgfctl.c | 14 ++++----
Xi/chgkmap.c | 2 -
Xi/chgprop.c | 2 -
Xi/exevents.c | 10 ++---
Xi/getbmap.c | 2 -
Xi/getdctl.c | 2 -
Xi/getfctl.c | 2 -
Xi/getprop.c | 2 -
Xi/getselev.c | 2 -
Xi/getvers.c | 4 +-
Xi/grabdev.c | 4 +-
Xi/grabdevb.c | 2 -
Xi/grabdevk.c | 2 -
Xi/gtmotion.c | 2 -
Xi/listdev.c | 2 -
Xi/opendev.c | 2 -
Xi/queryst.c | 2 -
Xi/selectev.c | 2 -
Xi/sendexev.c | 8 ++--
Xi/setbmap.c | 4 +-
Xi/setdval.c | 2 -
Xi/setmmap.c | 4 +-
Xi/xichangehierarchy.c | 2 -
Xi/xiproperty.c | 8 ++--
Xi/xiquerydevice.c | 13 ++++---
Xi/xiquerypointer.c | 2 -
Xi/xiselectev.c | 2 -
dbe/dbe.c | 2 -
dix/devices.c | 9 ++---
dix/dispatch.c | 56 ++++++++++++++++-----------------
dix/dixfonts.c | 12 +++----
dix/eventconvert.c | 10 ++---
dix/events.c | 4 +-
dix/extension.c | 2 -
dix/property.c | 6 +--
dix/swaprep.c | 4 +-
dix/window.c | 4 +-
exa/exa.c | 6 +--
glx/indirect_util.c | 4 +-
glx/rensize.c | 2 -
hw/dmx/dmx.c | 20 +++++------
hw/dmx/glxProxy/glxsingle.c | 2 -
hw/kdrive/ephyr/ephyrdriext.c | 14 ++++----
hw/kdrive/ephyr/ephyrhostglx.c | 2 -
hw/xfree86/common/xf86DGA.c | 2 -
hw/xfree86/dixmods/extmod/xf86dga2.c | 8 ++--
hw/xfree86/dixmods/extmod/xf86vmode.c | 42 ++++++++++++------------
hw/xfree86/dri/xf86dri.c | 14 ++++----
hw/xfree86/modes/xf86Modes.c | 2 -
hw/xfree86/os-support/linux/lnx_font.c | 2 -
hw/xfree86/xaa/xaaFillRect.c | 2 -
hw/xfree86/xaa/xaaImage.c | 6 +--
hw/xfree86/xaa/xaaPCache.c | 2 -
hw/xquartz/pseudoramiX.c | 2 -
hw/xquartz/xpr/xprCursor.c | 2 -
hw/xwin/wincursor.c | 14 +++-----
include/misc.h | 30 +++++++++++++++++
os/access.c | 4 +-
os/io.c | 6 +--
randr/rrcrtc.c | 14 ++++----
randr/rrmode.c | 4 +-
randr/rroutput.c | 8 ++--
randr/rrproperty.c | 8 ++--
randr/rrscreen.c | 8 ++--
randr/rrsdispatch.c | 4 +-
randr/rrxinerama.c | 2 -
record/record.c | 13 ++++---
render/render.c | 16 ++++-----
test/input.c | 39 ++++++++++++++++++++++
xfixes/cursor.c | 6 +--
xkb/xkb.c | 4 +-
84 files changed, 353 insertions(+), 283 deletions(-)
New commits:
commit e2226f3cd7d1bef598f9657b756a171b02f1a299
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 14:57:04 2009 +1000
dbe: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/dbe/dbe.c b/dbe/dbe.c
index b8f61e7..a4f853d 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -741,7 +741,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = length >> 2;
+ rep.length = bytes_to_int32(length);
rep.m = count;
if (client->swapped)
commit 3e1a054423c22f0e35f25127dde1ea8263892480
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 14:24:45 2009 +1000
record: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/record/record.c b/record/record.c
index 3c4bb9e..fd88552 100644
--- a/record/record.c
+++ b/record/record.c
@@ -372,7 +372,8 @@ RecordAProtocolElement(RecordContextPtr pContext, ClientPtr pClient,
replylen = pRep->length;
if (recordingClientSwapped) swapl(&replylen, n);
- replylen += numElemHeaders + (datalen >> 2) + (futurelen >> 2);
+ replylen += numElemHeaders + bytes_to_int32(datalen) +
+ bytes_to_int32(futurelen);
if (recordingClientSwapped) swapl(&replylen, n);
pRep->length = replylen;
} /* end if not continued reply */
@@ -480,7 +481,7 @@ RecordABigRequest(RecordContextPtr pContext, ClientPtr client, xReq *stuff)
(pointer)stuff, SIZEOF(xReq), bytesLeft);
/* reinsert the extended length field that was squished out */
- bigLength = client->req_len + (sizeof(bigLength) >> 2);
+ bigLength = client->req_len + bytes_to_int32(sizeof(bigLength));
if (client->swapped)
swapl(&bigLength, n);
RecordAProtocolElement(pContext, client, XRecordFromClient,
@@ -2279,8 +2280,8 @@ ProcRecordGetContext(ClientPtr client)
{
rep.nClients += pRCAP->numClients;
rep.length += pRCAP->numClients *
- ( (sizeof(xRecordClientInfo) >> 2) +
- pri->nRanges * (sizeof(xRecordRange) >> 2));
+ ( bytes_to_int32(sizeof(xRecordClientInfo)) +
+ pri->nRanges * bytes_to_int32(sizeof(xRecordRange)));
}
/* write the reply header */
@@ -2579,13 +2580,13 @@ SwapCreateRegister(xRecordRegisterClientsReq *stuff)
swapl(&stuff->nClients, n);
swapl(&stuff->nRanges, n);
pClientID = (XID *)&stuff[1];
- if (stuff->nClients > stuff->length - (sz_xRecordRegisterClientsReq >> 2))
+ if (stuff->nClients > stuff->length - bytes_to_int32(sz_xRecordRegisterClientsReq))
return BadLength;
for (i = 0; i < stuff->nClients; i++, pClientID++)
{
swapl(pClientID, n);
}
- if (stuff->nRanges > stuff->length - (sz_xRecordRegisterClientsReq >> 2)
+ if (stuff->nRanges > stuff->length - bytes_to_int32(sz_xRecordRegisterClientsReq)
- stuff->nClients)
return BadLength;
RecordSwapRanges((xRecordRange *)pClientID, stuff->nRanges);
commit 089c460058c4e6814d98d40179eb4c731f37fa80
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 14:22:40 2009 +1000
xkb: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/xkb/xkb.c b/xkb/xkb.c
index e4e84ce..c17250a 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -667,8 +667,8 @@ ProcXkbGetControls(ClientPtr client)
xkb = dev->key->xkbInfo->desc->ctrls;
rep.type = X_Reply;
- rep.length = (SIZEOF(xkbGetControlsReply)-
- SIZEOF(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xkbGetControlsReply)-
+ SIZEOF(xGenericReply));
rep.sequenceNumber = client->sequence;
rep.deviceID = ((DeviceIntPtr)dev)->id;
rep.numGroups = xkb->num_groups;
commit 0dc11da57562a7bbb6830ab657a2b818c596a537
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:41:29 2009 +1000
ephyr: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 6e915ab..84885d8 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -701,8 +701,8 @@ ProcXF86DRIOpenConnection (register ClientPtr client)
rep.busIdStringLength = 0;
if (busIdString)
rep.busIdStringLength = strlen(busIdString);
- rep.length = (SIZEOF(xXF86DRIOpenConnectionReply) - SIZEOF(xGenericReply) +
- ((rep.busIdStringLength + 3) & ~3)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) - SIZEOF(xGenericReply) +
+ pad_to_int32(rep.busIdStringLength));
rep.hSAREALow = (CARD32)(hSAREA & 0xffffffff);
#if defined(LONG64) && !defined(__linux__)
@@ -789,9 +789,9 @@ ProcXF86DRIGetClientDriverName (register ClientPtr client)
rep.clientDriverNameLength = 0;
if (clientDriverName)
rep.clientDriverNameLength = strlen(clientDriverName);
- rep.length = (SIZEOF(xXF86DRIGetClientDriverNameReply) -
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetClientDriverNameReply) -
SIZEOF(xGenericReply) +
- ((rep.clientDriverNameLength + 3) & ~3)) >> 2;
+ pad_to_int32(rep.clientDriverNameLength));
WriteToClient(client,
sizeof(xXF86DRIGetClientDriverNameReply), (char *)&rep);
@@ -1235,7 +1235,7 @@ ProcXF86DRIGetDrawableInfo (register ClientPtr client)
EPHYR_LOG ("num host clip rects:%d\n", (int)rep.numClipRects) ;
EPHYR_LOG ("num host back clip rects:%d\n", (int)rep.numBackClipRects) ;
- rep.length = ((rep.length + 3) & ~3) >> 2;
+ rep.length = bytes_to_int32(rep.length);
WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *)&rep);
@@ -1297,9 +1297,9 @@ ProcXF86DRIGetDeviceInfo (register ClientPtr client)
rep.length = 0;
if (rep.devPrivateSize) {
- rep.length = (SIZEOF(xXF86DRIGetDeviceInfoReply) -
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetDeviceInfoReply) -
SIZEOF(xGenericReply) +
- ((rep.devPrivateSize + 3) & ~3)) >> 2;
+ pad_to_int32(rep.devPrivateSize));
}
WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *)&rep);
diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index a05bba2..728687b 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -428,7 +428,7 @@ ephyrHostGLXSendClientInfo (int32_t a_major, int32_t a_minor,
req->minor = a_minor;
size = strlen (a_extension_list) + 1;
- req->length += (size + 3) >> 2;
+ req->length += bytes_to_int32(size);
req->numbytes = size;
Data (dpy, a_extension_list, size);
commit 34bfaa9d9ecd90cfe8413bc275179fdcc193eab3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:29:26 2009 +1000
xfixes: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 534c826..698e4d5 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -488,7 +488,7 @@ ProcXFixesGetCursorName (ClientPtr client)
len = strlen (str);
reply.type = X_Reply;
- reply.length = (len + 3) >> 2;
+ reply.length = bytes_to_int32(len);
reply.sequenceNumber = client->sequence;
reply.atom = pCursor->name;
reply.nbytes = len;
@@ -545,7 +545,7 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
npixels = width * height;
name = pCursor->name ? NameForAtom (pCursor->name) : "";
nbytes = strlen (name);
- nbytesRound = (nbytes + 3) & ~3;
+ nbytesRound = pad_to_int32(nbytes);
rep = xalloc (sizeof (xXFixesGetCursorImageAndNameReply) +
npixels * sizeof (CARD32) + nbytesRound);
if (!rep)
@@ -553,7 +553,7 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
rep->type = X_Reply;
rep->sequenceNumber = client->sequence;
- rep->length = npixels + (nbytesRound >> 2);
+ rep->length = npixels + bytes_to_int32(nbytesRound);
rep->width = width;
rep->height = height;
rep->x = x;
commit e216527107fda470b92b7e526f3db22465962a43
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:27:23 2009 +1000
render: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/render/render.c b/render/render.c
index 5622994..0e850e3 100644
--- a/render/render.c
+++ b/render/render.c
@@ -369,7 +369,7 @@ ProcRenderQueryPictFormats (ClientPtr client)
return BadAlloc;
reply->type = X_Reply;
reply->sequenceNumber = client->sequence;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+ reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
reply->numFormats = nformat;
reply->numScreens = numScreens;
reply->numDepths = ndepth;
@@ -537,7 +537,7 @@ ProcRenderQueryPictIndexValues (ClientPtr client)
reply->type = X_Reply;
reply->sequenceNumber = client->sequence;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+ reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
reply->numIndexValues = num;
values = (xIndexValue *) (reply + 1);
@@ -594,7 +594,7 @@ ProcRenderCreatePicture (ClientPtr client)
if (pFormat->depth != pDrawable->depth)
return BadMatch;
- len = client->req_len - (sizeof(xRenderCreatePictureReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xRenderCreatePictureReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -623,7 +623,7 @@ ProcRenderChangePicture (ClientPtr client)
VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
RenderErrBase + BadPicture);
- len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xRenderChangePictureReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -1235,7 +1235,7 @@ ProcRenderFreeGlyphs (ClientPtr client)
client->errorValue = stuff->glyphset;
return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
}
- nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2;
+ nglyph = bytes_to_int32((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq));
gids = (CARD32 *) (stuff + 1);
while (nglyph-- > 0)
{
@@ -1735,7 +1735,7 @@ ProcRenderQueryFilters (ClientPtr client)
nbytesName += 1 + strlen (ps->filterAliases[i].alias);
nnames = ps->nfilters + ps->nfilterAliases;
}
- len = ((nnames + 1) >> 1) + ((nbytesName + 3) >> 2);
+ len = ((nnames + 1) >> 1) + bytes_to_int32(nbytesName);
total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2);
reply = (xRenderQueryFiltersReply *) xalloc (total_bytes);
if (!reply)
@@ -1827,7 +1827,7 @@ ProcRenderSetPictureFilter (ClientPtr client)
VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
RenderErrBase + BadPicture);
name = (char *) (stuff + 1);
- params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3));
+ params = (xFixed *) (name + pad_to_int32(stuff->nbytes));
nparams = ((xFixed *) stuff + client->req_len) - params;
result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams);
return result;
@@ -1849,7 +1849,7 @@ ProcRenderCreateAnimCursor (ClientPtr client)
LEGAL_NEW_RESOURCE(stuff->cid, client);
if (client->req_len & 1)
return BadLength;
- ncursor = (client->req_len - (SIZEOF(xRenderCreateAnimCursorReq) >> 2)) >> 1;
+ ncursor = (client->req_len - (bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1;
cursors = xalloc (ncursor * (sizeof (CursorPtr) + sizeof (CARD32)));
if (!cursors)
return BadAlloc;
commit 1d6b71b8d0dc24355e84391ba413170a03ccdbf4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:25:39 2009 +1000
os: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/os/access.c b/os/access.c
index 3447876..6576579 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1458,7 +1458,7 @@ GetHosts (
for (host = validhosts; host; host = host->next)
{
nHosts++;
- n += (((host->len + 3) >> 2) << 2) + sizeof(xHostEntry);
+ n += pad_to_int32(host->len) + sizeof(xHostEntry);
}
if (n)
{
@@ -1474,7 +1474,7 @@ GetHosts (
((xHostEntry *)ptr)->length = len;
ptr += sizeof(xHostEntry);
acopy (host->addr, ptr, len);
- ptr += ((len + 3) >> 2) << 2;
+ ptr += pad_to_int32(len);
}
} else {
*data = NULL;
diff --git a/os/io.c b/os/io.c
index 45e1938..53b37b7 100644
--- a/os/io.c
+++ b/os/io.c
@@ -273,7 +273,7 @@ ReadRequestFromClient(ClientPtr client)
if (gotnow < sizeof(xBigReq))
{
/* Still need more data to tell just how big. */
- needed = sizeof(xBigReq) >> 2; /* needed is in CARD32s now */
+ needed = bytes_to_int32(sizeof(xBigReq)); /* needed is in CARD32s now */
need_header = TRUE;
}
else
@@ -377,7 +377,7 @@ ReadRequestFromClient(ClientPtr client)
{
move_header = TRUE;
if (gotnow < sizeof(xBigReq))
- needed = sizeof(xBigReq) >> 2;
+ needed = bytes_to_int32(sizeof(xBigReq));
else
needed = get_big_req_len(request, client);
}
@@ -445,7 +445,7 @@ ReadRequestFromClient(ClientPtr client)
oci->bufptr += (sizeof(xBigReq) - sizeof(xReq));
*(xReq *)oci->bufptr = *request;
oci->lenLastReq -= (sizeof(xBigReq) - sizeof(xReq));
- client->req_len -= (sizeof(xBigReq) - sizeof(xReq)) >> 2;
+ client->req_len -= bytes_to_int32(sizeof(xBigReq) - sizeof(xReq));
}
client->requestBuffer = (pointer)oci->bufptr;
#ifdef DEBUG_COMMUNICATION
commit 86b239ff9c4d01685c357ca2b1ef761d167e3224
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:24:27 2009 +1000
randr: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 32a0992..0e14b36 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -775,7 +775,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
int rc, i, j;
REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
- numOutputs = (stuff->length - (SIZEOF (xRRSetCrtcConfigReq) >> 2));
+ numOutputs = (stuff->length - bytes_to_int32(SIZEOF (xRRSetCrtcConfigReq)));
VERIFY_RR_CRTC(stuff->crtc, crtc, DixSetAttrAccess);
@@ -1205,7 +1205,7 @@ ProcRRGetCrtcGamma (ClientPtr client)
reply.type = X_Reply;
reply.sequenceNumber = client->sequence;
- reply.length = (len + 3) >> 2;
+ reply.length = bytes_to_int32(len);
reply.size = crtc->gammaSize;
if (client->swapped) {
swaps (&reply.sequenceNumber, n);
@@ -1234,7 +1234,7 @@ ProcRRSetCrtcGamma (ClientPtr client)
REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
- len = client->req_len - (sizeof (xRRSetCrtcGammaReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof (xRRSetCrtcGammaReq));
if (len < (stuff->size * 3 + 1) >> 1)
return BadLength;
@@ -1274,7 +1274,7 @@ ProcRRSetCrtcTransform (ClientPtr client)
filter = (char *) (stuff + 1);
nbytes = stuff->nbytesFilter;
- params = (xFixed *) (filter + ((nbytes + 3) & ~3));
+ params = (xFixed *) (filter + pad_to_int32(nbytes));
nparams = ((xFixed *) stuff + client->req_len) - params;
if (nparams < 0)
return BadLength;
@@ -1295,7 +1295,7 @@ transform_filter_length (RRTransformPtr transform)
return 0;
nbytes = strlen (transform->filter->name);
nparams = transform->nparams;
- return ((nbytes + 3) & ~3) + (nparams * sizeof (xFixed));
+ return pad_to_int32(nbytes) + (nparams * sizeof (xFixed));
}
static int
@@ -1334,7 +1334,7 @@ transform_encode (ClientPtr client, xRenderTransform *wire, PictTransform *pict)
{
xRenderTransform_from_PictTransform (wire, pict);
if (client->swapped)
- SwapLongs ((CARD32 *) wire, sizeof (xRenderTransform) >> 2);
+ SwapLongs ((CARD32 *) wire, bytes_to_int32(sizeof(xRenderTransform)));
}
int
@@ -1363,7 +1363,7 @@ ProcRRGetCrtcTransform (ClientPtr client)
extra = (char *) (reply + 1);
reply->type = X_Reply;
reply->sequenceNumber = client->sequence;
- reply->length = (CrtcTransformExtra + nextra) >> 2;
+ reply->length = bytes_to_int32(CrtcTransformExtra + nextra);
reply->hasTransforms = crtc->transforms;
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 2a10076..3d053bc 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -297,10 +297,10 @@ ProcRRCreateMode (ClientPtr client)
modeInfo = &stuff->modeInfo;
name = (char *) (stuff + 1);
- units_after = (stuff->length - (sizeof (xRRCreateModeReq) >> 2));
+ units_after = (stuff->length - bytes_to_int32(sizeof (xRRCreateModeReq)));
/* check to make sure requested name fits within the data provided */
- if ((int) (modeInfo->nameLength + 3) >> 2 > units_after)
+ if (bytes_to_int32(modeInfo->nameLength) > units_after)
return BadLength;
mode = RRModeCreateUser (pScreen, modeInfo, name, &error);
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 127497e..2eff8c1 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -455,7 +455,7 @@ ProcRRGetOutputInfo (ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = OutputInfoExtra >> 2;
+ rep.length = bytes_to_int32(OutputInfoExtra);
rep.timestamp = pScrPriv->lastSetTime.milliseconds;
rep.crtc = output->crtc ? output->crtc->id : None;
rep.mmWidth = output->mmWidth;
@@ -468,14 +468,14 @@ ProcRRGetOutputInfo (ClientPtr client)
rep.nClones = output->numClones;
rep.nameLength = output->nameLength;
- extraLen = ((output->numCrtcs +
+ extraLen = ((output->numCrtcs +
output->numModes + output->numUserModes +
output->numClones +
- ((rep.nameLength + 3) >> 2)) << 2);
+ bytes_to_int32(rep.nameLength)) << 2);
if (extraLen)
{
- rep.length += extraLen >> 2;
+ rep.length += bytes_to_int32(extraLen);
extra = xalloc (extraLen);
if (!extra)
return BadAlloc;
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 775d9e2..6187b85 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -429,7 +429,7 @@ ProcRRListOutputProperties (ClientPtr client)
return(BadAlloc);
rep.type = X_Reply;
- rep.length = (numProps * sizeof(Atom)) >> 2;
+ rep.length = bytes_to_int32(numProps * sizeof(Atom));
rep.sequenceNumber = client->sequence;
rep.nAtoms = numProps;
if (client->swapped)
@@ -510,7 +510,7 @@ ProcRRConfigureOutputProperty (ClientPtr client)
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
- num_valid = stuff->length - (sizeof (xRRConfigureOutputPropertyReq) >> 2);
+ num_valid = stuff->length - bytes_to_int32(sizeof (xRRConfigureOutputPropertyReq));
return RRConfigureOutputProperty (output, stuff->property,
stuff->pending, stuff->range,
FALSE, num_valid,
@@ -544,7 +544,7 @@ ProcRRChangeOutputProperty (ClientPtr client)
return BadValue;
}
len = stuff->nUnits;
- if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2))
+ if (len > bytes_to_int32((0xffffffff - sizeof(xChangePropertyReq))))
return BadLength;
sizeInBytes = format>>3;
totalSize = len * sizeInBytes;
@@ -708,7 +708,7 @@ ProcRRGetOutputProperty (ClientPtr client)
}
reply.bytesAfter = n - (ind + len);
reply.format = prop_value->format;
- reply.length = (len + 3) >> 2;
+ reply.length = bytes_to_int32(len);
if (prop_value->format)
reply.nItems = len / (prop_value->format / 8);
else
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index a919ffd..97b8b96 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -381,8 +381,8 @@ rrGetScreenResources(ClientPtr client, Bool query)
rep.length = (pScrPriv->numCrtcs +
pScrPriv->numOutputs +
- num_modes * (SIZEOF(xRRModeInfo) >> 2) +
- ((rep.nbytesNames + 3) >> 2));
+ num_modes * bytes_to_int32(SIZEOF(xRRModeInfo)) +
+ bytes_to_int32(rep.nbytesNames));
extraLen = rep.length << 2;
if (extraLen)
@@ -455,7 +455,7 @@ rrGetScreenResources(ClientPtr client, Bool query)
names += mode->mode.nameLength;
}
xfree (modes);
- assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length);
+ assert (bytes_to_int32((char *) names - (char *) extra) == rep.length);
}
if (client->swapped) {
@@ -726,7 +726,7 @@ ProcRRGetScreenInfo (ClientPtr client)
if (data8 - (CARD8 *) extra != extraLen)
FatalError ("RRGetScreenInfo bad extra len %ld != %ld\n",
(unsigned long)(data8 - (CARD8 *) extra), extraLen);
- rep.length = (extraLen + 3) >> 2;
+ rep.length = bytes_to_int32(extraLen);
}
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
diff --git a/randr/rrsdispatch.c b/randr/rrsdispatch.c
index f6821c3..e16090a 100644
--- a/randr/rrsdispatch.c
+++ b/randr/rrsdispatch.c
@@ -375,10 +375,10 @@ SProcRRSetCrtcTransform (ClientPtr client)
REQUEST_AT_LEAST_SIZE(xRRSetCrtcTransformReq);
swaps(&stuff->length, n);
swapl(&stuff->crtc, n);
- SwapLongs((CARD32 *)&stuff->transform, (sizeof(xRenderTransform)) >> 2);
+ SwapLongs((CARD32 *)&stuff->transform, bytes_to_int32(sizeof(xRenderTransform)));
swaps(&stuff->nbytesFilter, n);
filter = (char *)(stuff + 1);
- params = (CARD32 *) (filter + ((stuff->nbytesFilter + 3) & ~3));
+ params = (CARD32 *) (filter + pad_to_int32(stuff->nbytesFilter));
nparams = ((CARD32 *) stuff + client->req_len) - params;
if (nparams < 0)
return BadLength;
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index d81a857..97be7c1 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -313,7 +313,7 @@ ProcRRXineramaQueryScreens(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.number = RRXineramaScreenCount (pScreen);
- rep.length = rep.number * sz_XineramaScreenInfo >> 2;
+ rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
if(client->swapped) {
register int n;
swaps(&rep.sequenceNumber, n);
commit 7b9e84e320a6f6449fe7bc58a8d6a094ae37b86c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:20:21 2009 +1000
Xext: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index 09399b6..55e732a 100644
--- a/Xext/mbuf.c
+++ b/Xext/mbuf.c
@@ -430,7 +430,7 @@ ProcCreateImageBuffers (client)
int len, nbuf, i, err, rc;
REQUEST_AT_LEAST_SIZE (xMbufCreateImageBuffersReq);
- len = stuff->length - (sizeof(xMbufCreateImageBuffersReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xMbufCreateImageBuffersReq));
if (len == 0)
return BadLength;
rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
@@ -498,7 +498,7 @@ ProcDisplayImageBuffers (client)
REQUEST_AT_LEAST_SIZE (xMbufDisplayImageBuffersReq);
- nbuf = stuff->length - (sizeof (xMbufDisplayImageBuffersReq) >> 2);
+ nbuf = stuff->length - bytes_to_int32(sizeof (xMbufDisplayImageBuffersReq));
if (!nbuf)
return Success;
minDelay = stuff->minDelay;
@@ -592,7 +592,7 @@ ProcSetMBufferAttributes (client)
pMultibuffers = (MultibuffersPtr)LookupIDByType (pWin->drawable.id, MultibuffersResType);
if (!pMultibuffers)
return BadMatch;
- len = stuff->length - (sizeof (xMbufSetMBufferAttributesReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof (xMbufSetMBufferAttributesReq));
vmask = stuff->valueMask;
if (len != Ones (vmask))
return BadLength;
@@ -687,7 +687,7 @@ ProcSetBufferAttributes (client)
pMultibuffer = (MultibufferPtr) LookupIDByType (stuff->buffer, MultibufferResType);
if (!pMultibuffer)
return MultibufferErrorBase + MultibufferBadBuffer;
- len = stuff->length - (sizeof (xMbufSetBufferAttributesReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof (xMbufSetBufferAttributesReq));
vmask = stuff->valueMask;
if (len != Ones (vmask))
return BadLength;
@@ -787,7 +787,7 @@ ProcGetBufferInfo (client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = nInfo * (sizeof (xMbufBufferInfo) >> 2);
+ rep.length = nInfo * bytes_to_int32(sizeof (xMbufBufferInfo));
rep.normalInfo = nInfo;
rep.stereoInfo = 0;
if (client->swapped)
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 4ab6f6b..c5fb700 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -669,7 +669,7 @@ Bool PanoramiXCreateConnectionBlock(void)
length += (depth->nVisuals * sizeof(xVisualType));
}
- connSetupPrefix.length = length >> 2;
+ connSetupPrefix.length = bytes_to_int32(length);
for (i = 0; i < PanoramiXNumDepths; i++)
xfree(PanoramiXDepths[i].vids);
@@ -1053,7 +1053,7 @@ ProcXineramaQueryScreens(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.number = (noPanoramiXExtension) ? 0 : PanoramiXNumScreens;
- rep.length = rep.number * sz_XineramaScreenInfo >> 2;
+ rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
if (client->swapped) {
int n;
swaps (&rep.sequenceNumber, n);
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 8b51009..6834efb 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -74,7 +74,7 @@ int PanoramiXCreateWindow(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
- len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -179,7 +179,7 @@ int PanoramiXChangeWindowAttributes(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
- len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq));
if (Ones(stuff->valueMask) != len)
return BadLength;
@@ -456,7 +456,7 @@ int PanoramiXConfigureWindow(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
- len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -734,7 +734,7 @@ int PanoramiXCreateGC(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xCreateGCReq);
client->errorValue = stuff->gc;
- len = client->req_len - (sizeof(xCreateGCReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -813,7 +813,7 @@ int PanoramiXChangeGC(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xChangeGCReq);
- len = client->req_len - (sizeof(xChangeGCReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq));
if (Ones(stuff->mask) != len)
return BadLength;
@@ -1299,7 +1299,7 @@ int PanoramiXPolyPoint(ClientPtr client)
return (result == BadValue) ? BadGC : result;
isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
- npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
+ npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
if (npoint > 0) {
origPts = xalloc(npoint * sizeof(xPoint));
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
@@ -1359,7 +1359,7 @@ int PanoramiXPolyLine(ClientPtr client)
return (result == BadValue) ? BadGC : result;
isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
- npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
+ npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
if (npoint > 0){
origPts = xalloc(npoint * sizeof(xPoint));
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
@@ -1605,7 +1605,7 @@ int PanoramiXFillPoly(ClientPtr client)
isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
- count = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
+ count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
if (count > 0){
locPts = xalloc(count * sizeof(DDXPointRec));
memcpy((char *)locPts, (char *)&stuff[1], count * sizeof(DDXPointRec));
@@ -1895,7 +1895,7 @@ int PanoramiXGetImage(ClientPtr client)
}
- xgi.length = (length + 3) >> 2;
+ xgi.length = bytes_to_int32(length);
if (widthBytesLine == 0 || h == 0)
linesPerBuf = 0;
diff --git a/Xext/saver.c b/Xext/saver.c
index b59f769..06dbc73 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -875,7 +875,7 @@ ScreenSaverSetAttributes (ClientPtr client)
if (ret != Success)
return ret;
- len = stuff->length - (sizeof(xScreenSaverSetAttributesReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xScreenSaverSetAttributesReq));
if (Ones(stuff->mask) != len)
return BadLength;
if (!stuff->width || !stuff->height)
@@ -1267,7 +1267,7 @@ ProcScreenSaverSetAttributes (ClientPtr client)
if (status != Success)
return (status == BadValue) ? BadDrawable : status;
- len = stuff->length - (sizeof(xScreenSaverSetAttributesReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xScreenSaverSetAttributesReq));
if (Ones(stuff->mask) != len)
return BadLength;
diff --git a/Xext/security.c b/Xext/security.c
index bae95a3..8b72e17 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -450,9 +450,9 @@ ProcSecurityGenerateAuthorization(
/* check request length */
REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
- len = SIZEOF(xSecurityGenerateAuthorizationReq) >> 2;
- len += (stuff->nbytesAuthProto + (unsigned)3) >> 2;
- len += (stuff->nbytesAuthData + (unsigned)3) >> 2;
+ len = bytes_to_int32(SIZEOF(xSecurityGenerateAuthorizationReq));
+ len += bytes_to_int32(stuff->nbytesAuthProto);
+ len += bytes_to_int32(stuff->nbytesAuthData);
values = ((CARD32 *)stuff) + len;
len += Ones(stuff->valueMask);
if (client->req_len != len)
@@ -520,7 +520,7 @@ ProcSecurityGenerateAuthorization(
}
protoname = (char *)&stuff[1];
- protodata = protoname + ((stuff->nbytesAuthProto + (unsigned)3) >> 2);
+ protodata = protoname + bytes_to_int32(stuff->nbytesAuthProto);
/* call os layer to generate the authorization */
@@ -580,7 +580,7 @@ ProcSecurityGenerateAuthorization(
/* tell client the auth id and data */
rep.type = X_Reply;
- rep.length = (authdata_len + 3) >> 2;
+ rep.length = bytes_to_int32(authdata_len);
rep.sequenceNumber = client->sequence;
rep.authId = authId;
rep.dataLength = authdata_len;
@@ -688,10 +688,10 @@ SProcSecurityGenerateAuthorization(
swaps(&stuff->nbytesAuthProto, n);
swaps(&stuff->nbytesAuthData, n);
swapl(&stuff->valueMask, n);
- values_offset = ((stuff->nbytesAuthProto + (unsigned)3) >> 2) +
- ((stuff->nbytesAuthData + (unsigned)3) >> 2);
+ values_offset = bytes_to_int32(stuff->nbytesAuthProto) +
+ bytes_to_int32(stuff->nbytesAuthData);
if (values_offset >
- stuff->length - (sz_xSecurityGenerateAuthorizationReq >> 2))
+ stuff->length - bytes_to_int32(sz_xSecurityGenerateAuthorizationReq))
return BadLength;
values = (CARD32 *)(&stuff[1]) + values_offset;
nvalues = (((CARD32 *)stuff) + stuff->length) - values;
diff --git a/Xext/shape.c b/Xext/shape.c
index 5977296..a5ae455 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -1069,7 +1069,7 @@ ProcShapeGetRectangles (ClientPtr client)
}
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = (nrects * sizeof (xRectangle)) >> 2;
+ rep.length = bytes_to_int32(nrects * sizeof (xRectangle));
rep.ordering = YXBanded;
rep.nrects = nrects;
if (client->swapped) {
diff --git a/Xext/sync.c b/Xext/sync.c
index d7ab63c..a38ec7b 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -1179,7 +1179,7 @@ ProcSyncListSystemCounters(ClientPtr client)
{
char *name = SysCounterList[i]->pSysCounterInfo->name;
/* pad to 4 byte boundary */
- len += (sz_xSyncSystemCounter + strlen(name) + 3) & ~3;
+ len += pad_to_int32(sz_xSyncSystemCounter + strlen(name));
}
if (len)
@@ -1189,7 +1189,7 @@ ProcSyncListSystemCounters(ClientPtr client)
return BadAlloc;
}
- rep.length = len >> 2;
+ rep.length = bytes_to_int32(len);
if (client->swapped)
{
@@ -1223,7 +1223,7 @@ ProcSyncListSystemCounters(ClientPtr client)
pname_in_reply = ((char *)walklist) + sz_xSyncSystemCounter;
strncpy(pname_in_reply, psci->name, namelen);
walklist = (xSyncSystemCounter *) (((char *)walklist) +
- ((sz_xSyncSystemCounter + namelen + 3) & ~3));
+ pad_to_int32(sz_xSyncSystemCounter + namelen));
}
WriteToClient(client, sizeof(rep), (char *) &rep);
@@ -1600,7 +1600,7 @@ ProcSyncCreateAlarm(ClientPtr client)
LEGAL_NEW_RESOURCE(stuff->id, client);
vmask = stuff->valueMask;
- len = client->req_len - (sizeof(xSyncCreateAlarmReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xSyncCreateAlarmReq));
/* the "extra" call to Ones accounts for the presence of 64 bit values */
if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
return BadLength;
@@ -1681,7 +1681,7 @@ ProcSyncChangeAlarm(ClientPtr client)
return (status == BadValue) ? SyncErrorBase + XSyncBadAlarm : status;
vmask = stuff->valueMask;
- len = client->req_len - (sizeof(xSyncChangeAlarmReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xSyncChangeAlarmReq));
/* the "extra" call to Ones accounts for the presence of 64 bit values */
if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
return BadLength;
@@ -1720,7 +1720,7 @@ ProcSyncQueryAlarm(ClientPtr client)
return (rc == BadValue) ? SyncErrorBase + XSyncBadAlarm : rc;
rep.type = X_Reply;
- rep.length = (sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply));
rep.sequenceNumber = client->sequence;
pTrigger = &pAlarm->trigger;
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 7d4c697..9e0b5ea 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -629,7 +629,7 @@ ProcXF86BigfontQueryFont(
return BadAlloc;
}
reply->type = X_Reply;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+ reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
reply->sequenceNumber = client->sequence;
reply->minBounds = pFont->info.ink_minbounds;
reply->maxBounds = pFont->info.ink_maxbounds;
diff --git a/Xext/xres.c b/Xext/xres.c
index 5c04c11..9dd08b1 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -75,7 +75,7 @@ ProcXResQueryClients (ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.num_clients = num_clients;
- rep.length = rep.num_clients * sz_xXResClient >> 2;
+ rep.length = bytes_to_int32(rep.num_clients * sz_xXResClient);
if (client->swapped) {
int n;
swaps (&rep.sequenceNumber, n);
@@ -144,7 +144,7 @@ ProcXResQueryClientResources (ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.num_types = num_types;
- rep.length = rep.num_types * sz_xXResType >> 2;
+ rep.length = bytes_to_int32(rep.num_types * sz_xXResType);
if (client->swapped) {
int n;
swaps (&rep.sequenceNumber, n);
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8054230..d718951 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1283,7 +1283,7 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid)
}
rep.type = X_Reply;
- rep.length = (len + 3) >> 2;
+ rep.length = bytes_to_int32(len);
rep.sequenceNumber = client->sequence;
rep.context_len = len;
@@ -1510,8 +1510,8 @@ SELinuxPopulateItem(SELinuxListItemRec *i, PrivateRec **privPtr, CARD32 id,
return BadValue;
i->id = id;
- i->octx_len = (strlen(i->octx) + 4) >> 2;
- i->dctx_len = (strlen(i->dctx) + 4) >> 2;
+ i->octx_len = bytes_to_int32(strlen(i->octx) + 1);
+ i->dctx_len = bytes_to_int32(strlen(i->dctx) + 1);
*size += i->octx_len + i->dctx_len + 3;
return Success;
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index fcb61e4..3bff2ec 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -423,12 +423,12 @@ ProcXvQueryAdaptors(ClientPtr client)
pa = pxvs->pAdaptors;
while (na--)
{
- totalSize += (strlen(pa->name) + 3) & ~3;
+ totalSize += pad_to_int32(strlen(pa->name));
totalSize += pa->nFormats * sz_xvFormat;
pa++;
}
- rep.length = totalSize >> 2;
+ rep.length = bytes_to_int32(totalSize);
_WriteQueryAdaptorsReply(client, &rep);
@@ -498,11 +498,11 @@ ProcXvQueryEncodings(ClientPtr client)
totalSize = ne * sz_xvEncodingInfo;
while (ne--)
{
- totalSize += (strlen(pe->name) + 3) & ~3;
+ totalSize += pad_to_int32(strlen(pe->name));
pe++;
}
- rep.length = totalSize >> 2;
+ rep.length = bytes_to_int32(totalSize);
_WriteQueryEncodingsReply(client, &rep);
@@ -923,7 +923,7 @@ ProcXvQueryPortAttributes(ClientPtr client)
for(i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < pPort->pAdaptor->nAttributes; i++, pAtt++)
{
- rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L;
+ rep.text_size += pad_to_int32(strlen(pAtt->name) + 1);
}
rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo)
@@ -939,7 +939,7 @@ ProcXvQueryPortAttributes(ClientPtr client)
Info.flags = pAtt->flags;
Info.min = pAtt->min_value;
Info.max = pAtt->max_value;
- Info.size = (size + 3) & ~3L;
+ Info.size = pad_to_int32(size);
_WriteAttributeInfo(client, &Info);
@@ -999,7 +999,7 @@ ProcXvPutImage(ClientPtr client)
size = (*pPort->pAdaptor->ddQueryImageAttributes)(client,
pPort, pImage, &width, &height, NULL, NULL);
size += sizeof(xvPutImageReq);
- size = (size + 3) >> 2;
+ size = bytes_to_int32(size);
if((width < stuff->width) || (height < stuff->height))
return BadValue;
@@ -1203,7 +1203,7 @@ ProcXvListImageFormats(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.num_formats = pPort->pAdaptor->nImages;
- rep.length = pPort->pAdaptor->nImages * sz_xvImageFormatInfo >> 2;
+ rep.length = bytes_to_int32(pPort->pAdaptor->nImages * sz_xvImageFormatInfo);
_WriteListImageFormatsReply(client, &rep);
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 879a222..b7bb0fc 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -153,7 +153,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.num = (adaptor) ? adaptor->num_surfaces : 0;
- rep.length = rep.num * sizeof(xvmcSurfaceInfo) >> 2;
+ rep.length = bytes_to_int32(rep.num * sizeof(xvmcSurfaceInfo));
WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), (char*)&rep);
@@ -519,7 +519,7 @@ ProcXvMCListSubpictureTypes(ClientPtr client)
if(surface->compatible_subpictures)
rep.num = surface->compatible_subpictures->num_xvimages;
- rep.length = rep.num * sizeof(xvImageFormatInfo) >> 2;
+ rep.length = bytes_to_int32(rep.num * sizeof(xvImageFormatInfo));
WriteToClient(client, sizeof(xvmcListSubpictureTypesReply), (char*)&rep);
@@ -588,8 +588,8 @@ ProcXvMCGetDRInfo(ClientPtr client)
rep.major = pScreenPriv->major;
rep.minor = pScreenPriv->minor;
rep.patchLevel = pScreenPriv->patchLevel;
- rep.nameLen = (strlen(pScreenPriv->clientDriverName) + 4) >> 2;
- rep.busIDLen = (strlen(pScreenPriv->busID) + 4) >> 2;
+ rep.nameLen = bytes_to_int32(strlen(pScreenPriv->clientDriverName) + 1);
+ rep.busIDLen = bytes_to_int32(strlen(pScreenPriv->busID) + 1);
rep.length = rep.nameLen + rep.busIDLen;
rep.nameLen <<=2;
commit aa19d355125a10b1a385c8f134d68e79d3d609c7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Fri Jul 10 14:25:22 2009 +1000
xwin: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c
index bda057b..ce98162 100644
--- a/hw/xwin/wincursor.c
+++ b/hw/xwin/wincursor.c
@@ -43,8 +43,6 @@
extern Bool g_fSoftwareCursor;
-#define BYTE_COUNT(x) (((x) + 7) / 8)
-
#define BRIGHTNESS(x) (x##Red * 0.299 + x##Green * 0.587 + x##Blue * 0.114)
#if 0
@@ -199,7 +197,7 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
/* Get the number of bytes required to store the whole cursor image
* This is roughly (sm_cx * sm_cy) / 8
* round up to 8 pixel boundary so we can convert whole bytes */
- nBytes = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * pScreenPriv->cursor.sm_cy;
+ nBytes = bits_to_bytes(pScreenPriv->cursor.sm_cx) * pScreenPriv->cursor.sm_cy;
/* Get the effective width and height */
nCX = min(pScreenPriv->cursor.sm_cx, pCursor->bits->width);
@@ -214,11 +212,11 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
* The first is for an empty mask */
if (pCursor->bits->emptyMask)
{
- int x, y, xmax = BYTE_COUNT(nCX);
+ int x, y, xmax = bits_to_bytes(nCX);
for (y = 0; y < nCY; ++y)
for (x = 0; x < xmax; ++x)
{
- int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x;
+ int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;
pAnd[nWinPix] = 0;
@@ -230,11 +228,11 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
}
else
{
- int x, y, xmax = BYTE_COUNT(nCX);
+ int x, y, xmax = bits_to_bytes(nCX);
for (y = 0; y < nCY; ++y)
for (x = 0; x < xmax; ++x)
{
- int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x;
+ int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + x;
int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;
unsigned char mask = pCursor->bits->mask[nXPix];
@@ -323,7 +321,7 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
(*pCur++) = 0;
else /* Within X11 icon bounds */
{
- int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + (x/8);
+ int nWinPix = bits_to_bytes(pScreenPriv->cursor.sm_cx) * y + (x/8);
bit = pAnd[nWinPix];
bit = bit & (1<<(7-(x&7)));
commit 0b4e6af857bcc5513e4c19912a54656d4696e56d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:12:57 2009 +1000
xquartz: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index f4ceff3..1de7af6 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -307,7 +307,7 @@ static int ProcPseudoramiXQueryScreens(ClientPtr client)
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.number = noPseudoramiXExtension ? 0 : pseudoramiXNumScreens;
- rep.length = rep.number * sz_XineramaScreenInfo >> 2;
+ rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
if (client->swapped) {
register int n;
swaps (&rep.sequenceNumber, n);
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index 4345bee..8c47b67 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -128,7 +128,7 @@ load_cursor(CursorPtr src, int screen)
while (ycount-- > 0)
{
- xcount = (src->bits->width + 7) / 8;
+ xcount = bits_to_bytes(src->bits->width);
sptr = srow; mptr = mrow;
dptr = drow;
commit ad508c93c239a5ba8381000c031e96caf2769265
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:12:20 2009 +1000
xfree86: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index f83bcd5..25aa4f5 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -1178,7 +1178,7 @@ DGAGetOldDGAMode(int index)
w = pScrn->currentMode->HDisplay;
h = pScrn->currentMode->VDisplay;
- p = ((pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)) + 3) & ~3L;
+ p = pad_to_int32(pScrn->displayWidth * bits_to_bytes(pScrn->bitsPerPixel));
for(i = 0; i < pScreenPriv->numModes; i++) {
mode = &(pScreenPriv->modes[i]);
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 46aa8b8..6286659 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -159,7 +159,7 @@ ProcXDGAOpenFramebuffer(ClientPtr client)
}
nameSize = deviceName ? (strlen(deviceName) + 1) : 0;
- rep.length = (nameSize + 3) >> 2;
+ rep.length = bytes_to_int32(nameSize);
WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), (char *)&rep);
if(rep.length)
@@ -225,10 +225,10 @@ ProcXDGAQueryModes(ClientPtr client)
size = num * sz_xXDGAModeInfo;
for(i = 0; i < num; i++)
- size += (strlen(mode[i].name) + 4) & ~3L; /* plus NULL */
+ size += pad_to_int32(strlen(mode[i].name) + 1); /* plus NULL */
rep.number = num;
- rep.length = size >> 2;
+ rep.length = bytes_to_int32(size);
WriteToClient(client, sz_xXDGAQueryModesReply, (char*)&rep);
@@ -389,7 +389,7 @@ ProcXDGASetMode(ClientPtr client)
info.reserved1 = mode.reserved1;
info.reserved2 = mode.reserved2;
- rep.length = (sz_xXDGAModeInfo + info.name_size) >> 2;
+ rep.length = bytes_to_int32(sz_xXDGAModeInfo + info.name_size);
WriteToClient(client, sz_xXDGASetModeReply, (char*)&rep);
WriteToClient(client, sz_xXDGAModeInfo, (char*)(&info));
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index bd6c594..2e82f33 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -414,11 +414,11 @@ ProcXF86VidModeGetModeLine(ClientPtr client)
REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
rep.type = X_Reply;
if (ver < 2) {
- rep.length = (SIZEOF(xXF86OldVidModeGetModeLineReply) -
- SIZEOF(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86OldVidModeGetModeLineReply) -
+ SIZEOF(xGenericReply));
} else {
- rep.length = (SIZEOF(xXF86VidModeGetModeLineReply) -
- SIZEOF(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetModeLineReply) -
+ SIZEOF(xGenericReply));
}
rep.sequenceNumber = client->sequence;
@@ -670,10 +670,10 @@ ProcXF86VidModeAddModeLine(ClientPtr client)
if (ver < 2) {
REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
- len = client->req_len - (sizeof(xXF86OldVidModeAddModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
} else {
REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
- len = client->req_len - (sizeof(xXF86VidModeAddModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
}
if (len != stuff->privsize)
return BadLength;
@@ -809,10 +809,10 @@ ProcXF86VidModeDeleteModeLine(ClientPtr client)
if (ver < 2) {
REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
- len = client->req_len - (sizeof(xXF86OldVidModeDeleteModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
} else {
REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
- len = client->req_len - (sizeof(xXF86VidModeDeleteModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
}
if (len != stuff->privsize) {
if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
@@ -923,10 +923,10 @@ ProcXF86VidModeModModeLine(ClientPtr client)
if (ver < 2) {
REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
- len = client->req_len - (sizeof(xXF86OldVidModeModModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
} else {
REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
- len = client->req_len - (sizeof(xXF86VidModeModModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
}
if (len != stuff->privsize)
return BadLength;
@@ -1052,10 +1052,10 @@ ProcXF86VidModeValidateModeLine(ClientPtr client)
if (ver < 2) {
REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
len = client->req_len -
- (sizeof(xXF86OldVidModeValidateModeLineReq) >> 2);
+ bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
} else {
REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
- len = client->req_len - (sizeof(xXF86VidModeValidateModeLineReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
}
if (len != stuff->privsize)
return BadLength;
@@ -1107,8 +1107,8 @@ status_reply:
xfree(modetmp);
rep.type = X_Reply;
- rep.length = (SIZEOF(xXF86VidModeValidateModeLineReply)
- - SIZEOF(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
+ - SIZEOF(xGenericReply));
rep.sequenceNumber = client->sequence;
rep.status = status;
if (client->swapped) {
@@ -1185,10 +1185,10 @@ ProcXF86VidModeSwitchToMode(ClientPtr client)
if (ver < 2) {
REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
- len = client->req_len - (sizeof(xXF86OldVidModeSwitchToModeReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
} else {
REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
- len = client->req_len - (sizeof(xXF86VidModeSwitchToModeReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
}
if (len != stuff->privsize)
return BadLength;
@@ -1289,10 +1289,10 @@ ProcXF86VidModeGetMonitor(ClientPtr client)
VIDMODE_MON_MODEL, 0)).ptr);
else
rep.modelLength = 0;
- rep.length = (SIZEOF(xXF86VidModeGetMonitorReply) - SIZEOF(xGenericReply) +
+ rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetMonitorReply) - SIZEOF(xGenericReply) +
(nHsync + nVrefresh) * sizeof(CARD32) +
- ((rep.vendorLength + 3) & ~3) +
- ((rep.modelLength + 3) & ~3)) >> 2;
+ pad_to_int32(rep.vendorLength) +
+ pad_to_int32(rep.modelLength));
rep.sequenceNumber = client->sequence;
rep.nhsync = nHsync;
rep.nvsync = nVrefresh;
@@ -1413,8 +1413,8 @@ ProcXF86VidModeGetDotClocks(ClientPtr client)
numClocks = VidModeGetNumOfClocks(stuff->screen, &ClockProg);
rep.type = X_Reply;
- rep.length = (SIZEOF(xXF86VidModeGetDotClocksReply)
- - SIZEOF(xGenericReply) + numClocks) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
+ - SIZEOF(xGenericReply) + numClocks);
rep.sequenceNumber = client->sequence;
rep.clocks = numClocks;
rep.maxclocks = MAXCLOCKS;
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index 902fe12..d3e5e68 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -214,8 +214,8 @@ ProcXF86DRIOpenConnection(
rep.busIdStringLength = 0;
if (busIdString)
rep.busIdStringLength = strlen(busIdString);
- rep.length = (SIZEOF(xXF86DRIOpenConnectionReply) - SIZEOF(xGenericReply) +
- ((rep.busIdStringLength + 3) & ~3)) >> 2;
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) - SIZEOF(xGenericReply) +
+ pad_to_int32(rep.busIdStringLength));
rep.hSAREALow = (CARD32)(hSAREA & 0xffffffff);
#if defined(LONG64) && !defined(__linux__)
@@ -300,9 +300,9 @@ ProcXF86DRIGetClientDriverName(
rep.clientDriverNameLength = 0;
if (clientDriverName)
rep.clientDriverNameLength = strlen(clientDriverName);
- rep.length = (SIZEOF(xXF86DRIGetClientDriverNameReply) -
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetClientDriverNameReply) -
SIZEOF(xGenericReply) +
- ((rep.clientDriverNameLength + 3) & ~3)) >> 2;
+ pad_to_int32(rep.clientDriverNameLength));
WriteToClient(client,
sizeof(xXF86DRIGetClientDriverNameReply), (char *)&rep);
@@ -515,7 +515,7 @@ ProcXF86DRIGetDrawableInfo(
rep.length += sizeof(drm_clip_rect_t) * rep.numClipRects;
}
- rep.length = ((rep.length + 3) & ~3) >> 2;
+ rep.length = bytes_to_int32(rep.length);
WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *)&rep);
@@ -574,9 +574,9 @@ ProcXF86DRIGetDeviceInfo(
rep.length = 0;
if (rep.devPrivateSize) {
- rep.length = (SIZEOF(xXF86DRIGetDeviceInfoReply) -
+ rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetDeviceInfoReply) -
SIZEOF(xGenericReply) +
- ((rep.devPrivateSize + 3) & ~3)) >> 2;
+ pad_to_int32(rep.devPrivateSize));
}
WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *)&rep);
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 74d8648..0449af2 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -123,7 +123,7 @@ unsigned int
xf86ModeBandwidth(DisplayModePtr mode, int depth)
{
float a_active, a_total, active_percent, pixels_per_second;
- int bytes_per_pixel = (depth + 7) / 8;
+ int bytes_per_pixel = bits_to_bytes(depth);
if (!mode->HTotal || !mode->VTotal || !mode->Clock)
return 0;
diff --git a/hw/xfree86/os-support/linux/lnx_font.c b/hw/xfree86/os-support/linux/lnx_font.c
index 5b2696a..d6fc283 100644
--- a/hw/xfree86/os-support/linux/lnx_font.c
+++ b/hw/xfree86/os-support/linux/lnx_font.c
@@ -168,7 +168,7 @@ lnx_savefont(void)
return FALSE;
}
- size = (width + 7)/8 * 32 * charcount;
+ size = bits_to_bytes(width) * 32 * charcount;
fontdata = (unsigned char *)xnfalloc(size);
if (!fontdata) {
xf86Msg(X_WARNING,
diff --git a/hw/xfree86/xaa/xaaFillRect.c b/hw/xfree86/xaa/xaaFillRect.c
index 7c319bb..0b83ef3 100644
--- a/hw/xfree86/xaa/xaaFillRect.c
+++ b/hw/xfree86/xaa/xaaFillRect.c
@@ -812,7 +812,7 @@ WriteColumn(
src = pSrc + (yoff * srcwidth);
- dwords = ((w * Bpp) + 3) >> 2;
+ dwords = bytes_to_int32(w * Bpp);
if((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
((dwords * h) & 0x01)) {
diff --git a/hw/xfree86/xaa/xaaImage.c b/hw/xfree86/xaa/xaaImage.c
index 85461c8..4933bee 100644
--- a/hw/xfree86/xaa/xaaImage.c
+++ b/hw/xfree86/xaa/xaaImage.c
@@ -92,7 +92,7 @@ XAAWritePixmap32To24(
int trans
){
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
- int count, dwords = ((w * 3) + 3) >> 2;
+ int count, dwords = bytes_to_int32(w * 3);
CARD32 *src, *dst;
Bool PlusOne = FALSE;
@@ -227,7 +227,7 @@ XAAWritePixmap (
BAD_ALIGNMENT:
- dwords = ((w * Bpp) + 3) >> 2;
+ dwords = bytes_to_int32(w * Bpp);
if((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
((dwords * h) & 0x01)) {
@@ -351,7 +351,7 @@ XAAWritePixmapScanline (
BAD_ALIGNMENT:
- dwords = ((w * Bpp) + 3) >> 2;
+ dwords = bytes_to_int32(w * Bpp);
(*infoRec->SetupForScanlineImageWrite)(
pScrn, rop, planemask, trans, bpp, depth);
diff --git a/hw/xfree86/xaa/xaaPCache.c b/hw/xfree86/xaa/xaaPCache.c
index dbbeac6..7e3011b 100644
--- a/hw/xfree86/xaa/xaaPCache.c
+++ b/hw/xfree86/xaa/xaaPCache.c
@@ -1556,7 +1556,7 @@ XAACacheMonoStipple(ScrnInfoPtr pScrn, PixmapPtr pPix)
} else funcNo = 2;
pad = BitmapBytePad(pCache->w * bpp);
- dwords = pad >> 2;
+ dwords = bytes_to_int32(pad);
dstPtr = data = (unsigned char*)xalloc(pad * pCache->h);
srcPtr = (unsigned char*)pPix->devPrivate.ptr;
commit c20304226b3ca2f8d0a4f4866480b0d71913941c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:07:00 2009 +1000
glx: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/glx/indirect_util.c b/glx/indirect_util.c
index 58c194c..4430910 100644
--- a/glx/indirect_util.c
+++ b/glx/indirect_util.c
@@ -126,7 +126,7 @@ __glXSendReply( ClientPtr client, const void * data, size_t elements,
elements = 0;
}
else if ( (elements > 1) || always_array ) {
- reply_ints = ((elements * element_size) + 3) >> 2;
+ reply_ints = bytes_to_int32(elements * element_size);
}
__glXReply.length = reply_ints;
@@ -174,7 +174,7 @@ __glXSendReplySwap( ClientPtr client, const void * data, size_t elements,
elements = 0;
}
else if ( (elements > 1) || always_array ) {
- reply_ints = ((elements * element_size) + 3) >> 2;
+ reply_ints = bytes_to_int32(elements * element_size);
}
__glXReply.length = bswap_32( reply_ints );
diff --git a/glx/rensize.c b/glx/rensize.c
index 5c6b150..8a58e08 100644
--- a/glx/rensize.c
+++ b/glx/rensize.c
@@ -195,7 +195,7 @@ int __glXImageSize( GLenum format, GLenum type, GLenum target,
} else {
groupsPerRow = w;
}
- rowSize = (groupsPerRow + 7) >> 3;
+ rowSize = bits_to_bytes(groupsPerRow);
padding = (rowSize % alignment);
if (padding) {
rowSize += alignment - padding;
commit 87ce93c9973067255b4197d82772f83cd4ea5d27
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:06:47 2009 +1000
dmx: switch to byte counting functions
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 56e5bb6..87d408d 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -360,10 +360,10 @@ static int ProcDMXGetScreenAttributes(ClientPtr client)
rep.rootWindowYorigin = attr.rootWindowYorigin;
length = attr.displayName ? strlen(attr.displayName) : 0;
- paddedLength = (length + 3) & ~3;
+ paddedLength = pad_to_int32(length);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = paddedLength >> 2;
+ rep.length = bytes_to_int32(paddedLength);
rep.displayNameLength = length;
if (client->swapped) {
@@ -405,7 +405,7 @@ static int ProcDMXChangeScreensAttributes(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xDMXChangeScreensAttributesReq);
- len = client->req_len - (sizeof(xDMXChangeScreensAttributesReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xDMXChangeScreensAttributesReq));
if (len < stuff->screenCount + stuff->maskCount)
return BadLength;
@@ -474,8 +474,8 @@ static int ProcDMXAddScreen(ClientPtr client)
int paddedLength;
REQUEST_AT_LEAST_SIZE(xDMXAddScreenReq);
- paddedLength = (stuff->displayNameLength + 3) & ~3;
- len = client->req_len - (sizeof(xDMXAddScreenReq) >> 2);
+ paddedLength = pad_to_int32(stuff->displayNameLength);
+ len = client->req_len - bytes_to_int32(sizeof(xDMXAddScreenReq));
if (len != Ones(stuff->valueMask) + paddedLength/4)
return BadLength;
@@ -795,10 +795,10 @@ static int ProcDMXGetInputAttributes(ClientPtr client)
rep.detached = attr.detached;
length = attr.name ? strlen(attr.name) : 0;
- paddedLength = (length + 3) & ~3;
+ paddedLength = pad_to_int32(length);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.length = paddedLength >> 2;
+ rep.length = bytes_to_int32(paddedLength);
rep.nameLength = length;
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
@@ -828,7 +828,7 @@ static int ProcDMXAddInput(ClientPtr client)
int id = -1;
REQUEST_AT_LEAST_SIZE(xDMXAddInputReq);
- paddedLength = (stuff->displayNameLength + 3) & ~3;
+ paddedLength = pad_to_int32(stuff->displayNameLength);
len = client->req_len - (sizeof(xDMXAddInputReq) >> 2);
if (len != Ones(stuff->valueMask) + paddedLength/4)
return BadLength;
@@ -997,7 +997,7 @@ static int SProcDMXAddScreen(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xDMXAddScreenReq);
swapl(&stuff->displayNameLength, n);
swapl(&stuff->valueMask, n);
- paddedLength = (stuff->displayNameLength + 3) & ~3;
+ paddedLength = pad_to_int32(stuff->displayNameLength);
SwapLongs((CARD32 *)(stuff+1), LengthRestL(stuff) - paddedLength/4);
return ProcDMXAddScreen(client);
}
@@ -1077,7 +1077,7 @@ static int SProcDMXAddInput(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xDMXAddInputReq);
swapl(&stuff->displayNameLength, n);
swapl(&stuff->valueMask, n);
- paddedLength = (stuff->displayNameLength + 3) & ~3;
+ paddedLength = pad_to_int32(stuff->displayNameLength);
SwapLongs((CARD32 *)(stuff+1), LengthRestL(stuff) - paddedLength/4);
return ProcDMXAddInput(client);
}
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index 4d2d45b..dcc6040 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -902,7 +902,7 @@ int __glXDisp_ReadPixels(__GLXclientState *cl, GLbyte *pc)
else {
/* this is a GL_BITMAP pixel type, should copy bits */
int r;
- int src_rowsize = ((sw * ebits) + 7) / 8;
+ int src_rowsize = bits_to_bytes(sw * ebits);
int src_pad = src_rowsize % 4;
if ( src_pad ) {
src_rowsize += (4 - src_pad);
commit dc82e11e509ecf586d77c3e7c1325d515509ce51
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jul 6 12:03:34 2009 +1000
exa: switch to byte counting functions.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Acked-by: Michel Dänzer <michel at daenzer.net>
diff --git a/exa/exa.c b/exa/exa.c
index d04ea71..608c81f 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -236,7 +236,7 @@ exaSetAccelBlock(ExaScreenPrivPtr pExaScr, ExaPixmapPrivPtr pExaPixmap,
pExaPixmap->accel_blocked = 0;
if (pExaScr->info->maxPitchPixels) {
- int max_pitch = pExaScr->info->maxPitchPixels * (bpp + 7) / 8;
+ int max_pitch = pExaScr->info->maxPitchPixels * bits_to_bytes(bpp);
if (pExaPixmap->fb_pitch > max_pitch)
pExaPixmap->accel_blocked |= EXA_RANGE_PITCH;
@@ -258,9 +258,9 @@ exaSetFbPitch(ExaScreenPrivPtr pExaScr, ExaPixmapPrivPtr pExaPixmap,
int w, int h, int bpp)
{
if (pExaScr->info->flags & EXA_OFFSCREEN_ALIGN_POT && w != 1)
- pExaPixmap->fb_pitch = ((1 << (exaLog2(w - 1) + 1)) * bpp + 7) / 8;
+ pExaPixmap->fb_pitch = bits_to_bytes((1 << (exaLog2(w - 1) + 1)) * bpp);
else
- pExaPixmap->fb_pitch = (w * bpp + 7) / 8;
+ pExaPixmap->fb_pitch = bits_to_bytes(w * bpp);
pExaPixmap->fb_pitch = EXA_ALIGN(pExaPixmap->fb_pitch,
pExaScr->info->pixmapPitchAlign);
commit 2d35ea8d957a955e1200ba2b14424bddfe1f4148
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Fri Jul 3 16:50:03 2009 +1000
dix: switch to byte-counting functions.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/dix/devices.c b/dix/devices.c
index 9f2cb2b..4d006b1 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1532,7 +1532,7 @@ ProcSetModifierMapping(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
if (client->req_len != ((stuff->numKeyPerModifier << 1) +
- (sizeof (xSetModifierMappingReq) >> 2)))
+ bytes_to_int32(sizeof(xSetModifierMappingReq))))
return BadLength;
rep.type = X_Reply;
@@ -1591,7 +1591,7 @@ ProcChangeKeyboardMapping(ClientPtr client)
int rc;
REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
- len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xChangeKeyboardMappingReq));
if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
return BadLength;
@@ -1650,7 +1650,8 @@ ProcSetPointerMapping(ClientPtr client)
REQUEST(xSetPointerMappingReq);
REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
- if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2)
+ if (client->req_len !=
+ bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts))
return BadLength;
rep.type = X_Reply;
rep.length = 0;
@@ -2229,7 +2230,7 @@ ProcGetMotionEvents(ClientPtr client)
nEvents++;
}
}
- rep.length = nEvents * (sizeof(xTimecoord) >> 2);
+ rep.length = nEvents * bytes_to_int32(sizeof(xTimecoord));
rep.nEvents = nEvents;
WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
if (nEvents)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 86db92f..4df775d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -513,7 +513,7 @@ CreateConnectionBlock(void)
QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
lenofblock = sizeof(xConnSetup) +
- ((setup.nbytesVendor + 3) & ~3) +
+ pad_to_int32(setup.nbytesVendor) +
(setup.numFormats * sizeof(xPixmapFormat)) +
(setup.numRoots * sizeof(xWindowRoot));
ConnectionInfo = xalloc(lenofblock);
@@ -638,7 +638,7 @@ ProcCreateWindow(ClientPtr client)
rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq));
if (Ones(stuff->mask) != len)
return BadLength;
if (!stuff->width || !stuff->height)
@@ -681,7 +681,7 @@ ProcChangeWindowAttributes(ClientPtr client)
rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq));
if (len != Ones(stuff->valueMask))
return BadLength;
result = ChangeWindowAttributes(pWin,
@@ -885,7 +885,7 @@ ProcConfigureWindow(ClientPtr client)
DixManageAccess|DixSetAttrAccess);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq));
if (Ones((Mask)stuff->mask) != len)
return BadLength;
result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
@@ -1013,7 +1013,7 @@ ProcQueryTree(ClientPtr client)
}
reply.nChildren = numChildren;
- reply.length = (numChildren * sizeof(Window)) >> 2;
+ reply.length = bytes_to_int32(numChildren * sizeof(Window));
WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
if (numChildren)
@@ -1070,7 +1070,7 @@ ProcGetAtomName(ClientPtr client)
len = strlen(str);
memset(&reply, 0, sizeof(xGetAtomNameReply));
reply.type = X_Reply;
- reply.length = (len + 3) >> 2;
+ reply.length = bytes_to_int32(len);
reply.sequenceNumber = client->sequence;
reply.nameLength = len;
WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
@@ -1310,7 +1310,7 @@ ProcQueryFont(ClientPtr client)
}
reply->type = X_Reply;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+ reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
reply->sequenceNumber = client->sequence;
QueryFont( pFont, reply, nprotoxcistructs);
@@ -1344,7 +1344,7 @@ ProcQueryTextExtents(ClientPtr client)
if (rc != Success)
return (rc == BadValue) ? BadFont: rc;
- length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
+ length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq));
length = length << 1;
if (stuff->oddLength)
{
@@ -1512,7 +1512,7 @@ ProcCreateGC(ClientPtr client)
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xCreateGCReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq));
if (len != Ones(stuff->mask))
return BadLength;
pGC = (GC *)CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error,
@@ -1537,7 +1537,7 @@ ProcChangeGC(ClientPtr client)
if (result != Success)
return result;
- len = client->req_len - (sizeof(xChangeGCReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq));
if (len != Ones(stuff->mask))
return BadLength;
@@ -1787,7 +1787,7 @@ ProcPolyPoint(ClientPtr client)
return BadValue;
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
+ npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
if (npoint)
(*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
(xPoint *) &stuff[1]);
@@ -1810,7 +1810,7 @@ ProcPolyLine(ClientPtr client)
return BadValue;
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
+ npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
if (npoint > 1)
(*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint,
(DDXPointPtr) &stuff[1]);
@@ -1898,7 +1898,7 @@ ProcFillPoly(ClientPtr client)
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
+ things = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
if (things)
(*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
stuff->coordMode, things,
@@ -2042,8 +2042,8 @@ ProcPutImage(ClientPtr client)
tmpImage = (char *)&stuff[1];
lengthProto = length;
- if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) +
- (sizeof(xPutImageReq) >> 2)) != client->req_len)
+ if ((bytes_to_int32(lengthProto * stuff->height) +
+ bytes_to_int32(sizeof(xPutImageReq))) != client->req_len)
return BadLength;
ReformatImage (tmpImage, lengthProto * stuff->height,
@@ -2143,7 +2143,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
*(xGetImageReply *)pBuf = xgi;
pBuf += sz_xGetImageReply;
} else {
- xgi.length = (xgi.length + 3) >> 2;
+ xgi.length = bytes_to_int32(xgi.length);
if (widthBytesLine == 0 || height == 0)
linesPerBuf = 0;
else if (widthBytesLine >= IMAGE_BUFSIZE)
@@ -2705,7 +2705,7 @@ ProcAllocColorCells (ClientPtr client)
#endif
{
accr.type = X_Reply;
- accr.length = length >> 2;
+ accr.length = bytes_to_int32(length);
accr.sequenceNumber = client->sequence;
accr.nPixels = npixels;
accr.nMasks = nmasks;
@@ -2769,7 +2769,7 @@ ProcAllocColorPlanes(ClientPtr client)
else
return rc;
}
- acpr.length = length >> 2;
+ acpr.length = bytes_to_int32(length);
#ifdef PANORAMIX
if (noPanoramiXExtension || !pcmp->pScreen->myNum)
#endif
@@ -2804,7 +2804,7 @@ ProcFreeColors(ClientPtr client)
if(pcmp->flags & AllAllocated)
return(BadAccess);
- count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
+ count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq));
rc = FreeColors(pcmp, client->index, count,
(Pixel *)&stuff[1], (Pixel)stuff->planeMask);
if (client->noClientException != Success)
@@ -2907,7 +2907,7 @@ ProcQueryColors(ClientPtr client)
xrgb *prgbs;
xQueryColorsReply qcr;
- count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
+ count = bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq));
prgbs = xcalloc(1, count * sizeof(xrgb));
if(!prgbs && count)
return(BadAlloc);
@@ -2924,7 +2924,7 @@ ProcQueryColors(ClientPtr client)
}
memset(&qcr, 0, sizeof(xQueryColorsReply));
qcr.type = X_Reply;
- qcr.length = (count * sizeof(xrgb)) >> 2;
+ qcr.length = bytes_to_int32(count * sizeof(xrgb));
qcr.sequenceNumber = client->sequence;
qcr.nColors = count;
WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
@@ -3294,7 +3294,7 @@ ProcListHosts(ClientPtr client)
reply.type = X_Reply;
reply.sequenceNumber = client->sequence;
reply.nHosts = nHosts;
- reply.length = len >> 2;
+ reply.length = bytes_to_int32(len);
WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
if (nHosts)
{
@@ -3427,7 +3427,7 @@ ProcGetFontPath(ClientPtr client)
reply.type = X_Reply;
reply.sequenceNumber = client->sequence;
- reply.length = (stringLens + numpaths + 3) >> 2;
+ reply.length = bytes_to_int32(stringLens + numpaths);
reply.nPaths = numpaths;
WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
@@ -3656,7 +3656,7 @@ ClientPtr NextAvailableClient(pointer ospriv)
return (ClientPtr)NULL;
}
data.reqType = 1;
- data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
+ data.length = bytes_to_int32(sz_xReq + sz_xConnClientPrefix);
if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
{
FreeClientResources(client);
@@ -3696,8 +3696,8 @@ ProcInitialConnection(ClientPtr client)
SwapConnClientPrefix(prefix);
}
stuff->reqType = 2;
- stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) +
- ((prefix->nbytesAuthString + (unsigned)3) >> 2);
+ stuff->length += bytes_to_int32(prefix->nbytesAuthProto) +
+ bytes_to_int32(prefix->nbytesAuthString);
if (client->swapped)
{
swaps(&stuff->length, whichbyte);
@@ -3721,7 +3721,7 @@ SendConnSetup(ClientPtr client, char *reason)
csp.success = xFalse;
csp.lengthReason = strlen(reason);
- csp.length = (csp.lengthReason + (unsigned)3) >> 2;
+ csp.length = bytes_to_int32(csp.lengthReason);
csp.majorVersion = X_PROTOCOL;
csp.minorVersion = X_PROTOCOL_REVISION;
if (client->swapped)
@@ -3812,7 +3812,7 @@ ProcEstablishConnection(ClientPtr client)
prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
auth_proto = (char *)prefix + sz_xConnClientPrefix;
- auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
+ auth_string = auth_proto + pad_to_int32(prefix->nbytesAuthProto);
if ((prefix->majorVersion != X_PROTOCOL) ||
(prefix->minorVersion != X_PROTOCOL_REVISION))
reason = "Protocol version mismatch";
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 8b6e7a3..7d7ae71 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -792,7 +792,7 @@ finish:
memset(&reply, 0, sizeof(xListFontsReply));
reply.type = X_Reply;
- reply.length = (stringLens + nnames + 3) >> 2;
+ reply.length = bytes_to_int32(stringLens + nnames);
reply.nFonts = nnames;
reply.sequenceNumber = client->sequence;
@@ -817,7 +817,7 @@ finish:
}
}
nnames = reply.nFonts;
- reply.length = (stringLens + nnames + 3) >> 2;
+ reply.length = bytes_to_int32(stringLens + nnames);
client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply);
(void) WriteToClient(client, stringLens + nnames, bufferStart);
@@ -1057,9 +1057,9 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
namelen = strlen(name);
}
reply->type = X_Reply;
- reply->length = (sizeof *reply - sizeof(xGenericReply) +
+ reply->length = bytes_to_int32(sizeof *reply - sizeof(xGenericReply) +
pFontInfo->nprops * sizeof(xFontProp) +
- namelen + 3) >> 2;
+ namelen);
reply->sequenceNumber = client->sequence;
reply->nameLength = namelen;
reply->minBounds = pFontInfo->ink_minbounds;
@@ -1097,8 +1097,8 @@ finish:
bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply));
finalReply.type = X_Reply;
finalReply.sequenceNumber = client->sequence;
- finalReply.length = (sizeof(xListFontsWithInfoReply)
- - sizeof(xGenericReply)) >> 2;
+ finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply)
+ - sizeof(xGenericReply));
WriteSwappedDataToClient(client, length, &finalReply);
bail:
if (c->slept)
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index a65bf68..8d9a329 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -389,13 +389,13 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
/* FIXME: this should just send the buttons we have, not MAX_BUTTONs. Same
* with MAX_VALUATORS below */
/* btlen is in 4 byte units */
- btlen = (((MAX_BUTTONS + 7)/8) + 3)/4;
+ btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS));
len += btlen * 4; /* buttonmask len */
vallen = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0]));
len += vallen * 2 * sizeof(uint32_t); /* axisvalues */
- vallen = (((MAX_VALUATORS + 7)/8) + 3)/4;
+ vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */
*xi = xcalloc(1, len);
@@ -404,7 +404,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
xde->extension = IReqCode;
xde->evtype = GetXI2Type((InternalEvent*)ev);
xde->time = ev->time;
- xde->length = (len - sizeof(xEvent) + 3)/4;
+ xde->length = bytes_to_int32(len - sizeof(xEvent));
xde->detail = ev->detail.button;
xde->root = ev->root;
xde->buttons_len = btlen;
@@ -459,7 +459,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0]));
len += nvals * (2 * sizeof(uint32_t)) * 2; /* 8 byte per valuator, once
raw, once processed */
- vallen = (((MAX_VALUATORS + 7)/8) + 3)/4;
+ vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */
*xi = xcalloc(1, len);
@@ -468,7 +468,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
raw->extension = IReqCode;
raw->evtype = GetXI2Type((InternalEvent*)ev);
raw->time = ev->time;
- raw->length = (len - sizeof(xEvent) + 3)/4;
+ raw->length = bytes_to_int32(len - sizeof(xEvent));
raw->eventtype = ev->subtype;
raw->detail = ev->detail.button;
raw->deviceid = ev->deviceid;
diff --git a/dix/events.c b/dix/events.c
index 52f8b0d..91a0833 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4221,8 +4221,8 @@ DeviceEnterLeaveEvent(
(mode == XINotifyPassiveUngrab && type == XI_Enter))
return;
- btlen = (mouse->button) ? (mouse->button->numButtons + 7)/8 : 0;
- btlen = (btlen + 3)/4;
+ btlen = (mouse->button) ? bits_to_bytes(mouse->button->numButtons) : 0;
+ btlen = bytes_to_int32(btlen);
len = sizeof(xXIEnterEvent) + btlen * 4;
event = xcalloc(1, len);
diff --git a/dix/extension.c b/dix/extension.c
index c768ccb..fb83af1 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -324,7 +324,7 @@ ProcListExtensions(ClientPtr client)
for (j = extensions[i]->num_aliases; --j >= 0;)
total_length += strlen(extensions[i]->aliases[j]) + 1;
}
- reply.length = (total_length + 3) >> 2;
+ reply.length = bytes_to_int32(total_length);
buffer = bufptr = xalloc(total_length);
if (!buffer)
return(BadAlloc);
diff --git a/dix/property.c b/dix/property.c
index d63b8f4..20c18d7 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -218,7 +218,7 @@ ProcChangeProperty(ClientPtr client)
return BadValue;
}
len = stuff->nUnits;
- if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2))
+ if (len > bytes_to_int32(0xffffffff - sizeof(xChangePropertyReq)))
return BadLength;
sizeInBytes = format>>3;
totalSize = len * sizeInBytes;
@@ -532,7 +532,7 @@ ProcGetProperty(ClientPtr client)
reply.bytesAfter = n - (ind + len);
reply.format = pProp->format;
- reply.length = (len + 3) >> 2;
+ reply.length = bytes_to_int32(len);
reply.nItems = len / (pProp->format / 8 );
reply.propertyType = pProp->type;
@@ -606,7 +606,7 @@ ProcListProperties(ClientPtr client)
xlpr.type = X_Reply;
xlpr.nProperties = numProps;
- xlpr.length = (numProps * sizeof(Atom)) >> 2;
+ xlpr.length = bytes_to_int32(numProps * sizeof(Atom));
xlpr.sequenceNumber = client->sequence;
WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
if (numProps)
diff --git a/dix/swaprep.c b/dix/swaprep.c
index 8624216..12c6dbd 100644
--- a/dix/swaprep.c
+++ b/dix/swaprep.c
@@ -731,7 +731,7 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf)
int len = host->length;
char n;
swaps (&host->length, n);
- bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2);
+ bufT += sizeof (xHostEntry) + pad_to_int32(len);
}
(void)WriteToClient (pClient, size, buf);
}
@@ -1222,7 +1222,7 @@ SwapConnSetupInfo(
pInfoT += sizeof(xConnSetup);
/* Copy the vendor string */
- i = (pConnSetup->nbytesVendor + 3) & ~3;
+ i = pad_to_int32(pConnSetup->nbytesVendor);
memcpy(pInfoT, pInfo, i);
pInfo += i;
pInfoT += i;
diff --git a/dix/window.c b/dix/window.c
index 99b594b..32e26d9 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1457,8 +1457,8 @@ GetWindowAttributes(WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply
wa->backingStore = NotUseful;
else
wa->backingStore = pWin->backingStore;
- wa->length = (sizeof(xGetWindowAttributesReply) -
- sizeof(xGenericReply)) >> 2;
+ wa->length = bytes_to_int32(sizeof(xGetWindowAttributesReply) -
+ sizeof(xGenericReply));
wa->sequenceNumber = client->sequence;
wa->backingBitPlanes = wBackingBitPlanes (pWin);
wa->backingPixel = wBackingPixel (pWin);
commit 7dd415aa6a3959f15276741db168ba264948ecfe
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Fri Jul 3 13:57:14 2009 +1000
Xi: use byte-counting macros instead of manual calculation.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index 89e5a2d..901a0e4 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -142,7 +142,7 @@ ProcXChangeDeviceControl(ClientPtr client)
REQUEST(xChangeDeviceControlReq);
REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
- len = stuff->length - (sizeof(xChangeDeviceControlReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceControlReq));
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
if (ret != Success)
goto out;
@@ -155,8 +155,8 @@ ProcXChangeDeviceControl(ClientPtr client)
switch (stuff->control) {
case DEVICE_RESOLUTION:
r = (xDeviceResolutionCtl *) & stuff[1];
- if ((len < (sizeof(xDeviceResolutionCtl) >> 2)) ||
- (len != (sizeof(xDeviceResolutionCtl) >> 2) + r->num_valuators)) {
+ if ((len < bytes_to_int32(sizeof(xDeviceResolutionCtl))) ||
+ (len != bytes_to_int32(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) {
ret = BadLength;
goto out;
}
diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index e193e13..9189702 100644
--- a/Xi/chgfctl.c
+++ b/Xi/chgfctl.c
@@ -441,14 +441,14 @@ ProcXChangeFeedbackControl(ClientPtr client)
REQUEST(xChangeFeedbackControlReq);
REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
- len = stuff->length - (sizeof(xChangeFeedbackControlReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xChangeFeedbackControlReq));
rc = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
if (rc != Success)
return rc;
switch (stuff->feedbackid) {
case KbdFeedbackClass:
- if (len != (sizeof(xKbdFeedbackCtl) >> 2))
+ if (len != bytes_to_int32(sizeof(xKbdFeedbackCtl)))
return BadLength;
for (k = dev->kbdfeed; k; k = k->next)
@@ -457,7 +457,7 @@ ProcXChangeFeedbackControl(ClientPtr client)
(xKbdFeedbackCtl *) & stuff[1]);
break;
case PtrFeedbackClass:
- if (len != (sizeof(xPtrFeedbackCtl) >> 2))
+ if (len != bytes_to_int32(sizeof(xPtrFeedbackCtl)))
return BadLength;
for (p = dev->ptrfeed; p; p = p->next)
@@ -473,7 +473,7 @@ ProcXChangeFeedbackControl(ClientPtr client)
if (client->swapped) {
swaps(&f->num_keysyms, n);
}
- if (len != ((sizeof(xStringFeedbackCtl) >> 2) + f->num_keysyms))
+ if (len != (bytes_to_int32(sizeof(xStringFeedbackCtl)) + f->num_keysyms))
return BadLength;
for (s = dev->stringfeed; s; s = s->next)
@@ -483,7 +483,7 @@ ProcXChangeFeedbackControl(ClientPtr client)
break;
}
case IntegerFeedbackClass:
- if (len != (sizeof(xIntegerFeedbackCtl) >> 2))
+ if (len != bytes_to_int32(sizeof(xIntegerFeedbackCtl)))
return BadLength;
for (i = dev->intfeed; i; i = i->next)
@@ -492,7 +492,7 @@ ProcXChangeFeedbackControl(ClientPtr client)
(xIntegerFeedbackCtl *)&stuff[1]);
break;
case LedFeedbackClass:
- if (len != (sizeof(xLedFeedbackCtl) >> 2))
+ if (len != bytes_to_int32(sizeof(xLedFeedbackCtl)))
return BadLength;
for (l = dev->leds; l; l = l->next)
@@ -501,7 +501,7 @@ ProcXChangeFeedbackControl(ClientPtr client)
(xLedFeedbackCtl *) & stuff[1]);
break;
case BellFeedbackClass:
- if (len != (sizeof(xBellFeedbackCtl) >> 2))
+ if (len != bytes_to_int32(sizeof(xBellFeedbackCtl)))
return BadLength;
for (b = dev->bell; b; b = b->next)
diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
index 854c17f..e4b9e15 100644
--- a/Xi/chgkmap.c
+++ b/Xi/chgkmap.c
@@ -107,7 +107,7 @@ ProcXChangeDeviceKeyMapping(ClientPtr client)
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
if (ret != Success)
return ret;
- len = stuff->length - (sizeof(xChangeDeviceKeyMappingReq) >> 2);
+ len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceKeyMappingReq));
ret = ChangeKeyMapping(client, dev, len, DeviceMappingNotify,
stuff->firstKeyCode, stuff->keyCodes,
diff --git a/Xi/chgprop.c b/Xi/chgprop.c
index d8e37a7..d24a246 100644
--- a/Xi/chgprop.c
+++ b/Xi/chgprop.c
@@ -104,7 +104,7 @@ ProcXChangeDeviceDontPropagateList(ClientPtr client)
REQUEST(xChangeDeviceDontPropagateListReq);
REQUEST_AT_LEAST_SIZE(xChangeDeviceDontPropagateListReq);
- if (stuff->length != (sizeof(xChangeDeviceDontPropagateListReq) >> 2) +
+ if (stuff->length != bytes_to_int32(sizeof(xChangeDeviceDontPropagateListReq)) +
stuff->count)
return BadLength;
diff --git a/Xi/exevents.c b/Xi/exevents.c
index c575bb4..85baa03 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -686,7 +686,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged
{
len += sizeof(xXIButtonInfo);
len += dce->buttons.num_buttons * sizeof(Atom); /* button names */
- len += ((((dce->buttons.num_buttons + 7)/8) + 3)/4) * 4;
+ len += pad_to_int32(bits_to_bytes(dce->buttons.num_buttons));
}
if (dce->num_valuators)
len += sizeof(xXIValuatorInfo) * dce->num_valuators;
@@ -714,7 +714,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged
dcce->sourceid = device->id;
dcce->reason = (dce->flags & DEVCHANGE_DEVICE_CHANGE) ? XIDeviceChange : XISlaveSwitch;
dcce->num_classes = 0;
- dcce->length = (len - sizeof(xEvent))/4;
+ dcce->length = bytes_to_int32(len - sizeof(xEvent));
ptr = (char*)&dcce[1];
if (dce->buttons.num_buttons)
@@ -1249,15 +1249,15 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
mouse = (IsMaster(dev) || dev->u.master) ? GetMaster(dev, MASTER_POINTER) : dev;
/* XI 2 event */
- btlen = (mouse->button) ? (mouse->button->numButtons + 7)/8 : 0;
- btlen = (btlen + 3)/4;
+ btlen = (mouse->button) ? bits_to_bytes(mouse->button->numButtons) : 0;
+ btlen = bytes_to_int32(btlen);
len = sizeof(xXIFocusInEvent) + btlen * 4;
xi2event = xcalloc(1, len);
xi2event->type = GenericEvent;
xi2event->extension = IReqCode;
xi2event->evtype = type;
- xi2event->length = (len - sizeof(xEvent))/4;
+ xi2event->length = bytes_to_int32(len - sizeof(xEvent));
xi2event->buttons_len = btlen;
xi2event->detail = detail;
xi2event->time = currentTime.milliseconds;
diff --git a/Xi/getbmap.c b/Xi/getbmap.c
index 4a788c6..e2d5897 100644
--- a/Xi/getbmap.c
+++ b/Xi/getbmap.c
@@ -109,7 +109,7 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
return BadMatch;
rep.nElts = b->numButtons;
- rep.length = (rep.nElts + (4 - 1)) / 4;
+ rep.length = bytes_to_int32(rep.nElts);
WriteReplyToClient(client, sizeof(xGetDeviceButtonMappingReply), &rep);
(void)WriteToClient(client, rep.nElts, (char *)&b->map[1]);
return Success;
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index abb4f99..68181fa 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -306,7 +306,7 @@ ProcXGetDeviceControl(ClientPtr client)
break;
}
- rep.length = (total_length + 3) >> 2;
+ rep.length = bytes_to_int32(total_length);
WriteReplyToClient(client, sizeof(xGetDeviceControlReply), &rep);
WriteToClient(client, total_length, savbuf);
xfree(savbuf);
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 3a6dd45..607765e 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -358,7 +358,7 @@ ProcXGetFeedbackControl(ClientPtr client)
for (b = dev->bell; b; b = b->next)
CopySwapBellFeedback(client, b, &buf);
- rep.length = (total_length + 3) >> 2;
+ rep.length = bytes_to_int32(total_length);
WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
WriteToClient(client, total_length, savbuf);
xfree(savbuf);
diff --git a/Xi/getprop.c b/Xi/getprop.c
index dfa27f5..1f28a8a 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -120,7 +120,7 @@ ProcXGetDeviceDontPropagateList(ClientPtr client)
if (count) {
rep.count = count;
buf = (XEventClass *) xalloc(rep.count * sizeof(XEventClass));
- rep.length = (rep.count * sizeof(XEventClass) + 3) >> 2;
+ rep.length = bytes_to_int32(rep.count * sizeof(XEventClass));
tbuf = buf;
for (i = 0; i < EMASKSIZE; i++)
diff --git a/Xi/getselev.c b/Xi/getselev.c
index ea9bd9b..90f6284 100644
--- a/Xi/getselev.c
+++ b/Xi/getselev.c
@@ -131,7 +131,7 @@ ProcXGetSelectedExtensionEvents(ClientPtr client)
total_length = (rep.all_clients_count + rep.this_client_count) *
sizeof(XEventClass);
- rep.length = (total_length + 3) >> 2;
+ rep.length = bytes_to_int32(total_length);
buf = (XEventClass *) xalloc(total_length);
tclient = buf;
diff --git a/Xi/getvers.c b/Xi/getvers.c
index c8eacc1..c8e9ebc 100644
--- a/Xi/getvers.c
+++ b/Xi/getvers.c
@@ -96,8 +96,8 @@ ProcXGetExtensionVersion(ClientPtr client)
REQUEST(xGetExtensionVersionReq);
REQUEST_AT_LEAST_SIZE(xGetExtensionVersionReq);
- if (stuff->length != (sizeof(xGetExtensionVersionReq) +
- stuff->nbytes + 3) >> 2)
+ if (stuff->length != bytes_to_int32(sizeof(xGetExtensionVersionReq) +
+ stuff->nbytes))
return BadLength;
memset(&rep, 0, sizeof(xGetExtensionVersionReply));
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index e1d430a..a7e46fe 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -84,7 +84,7 @@ SProcXGrabDevice(ClientPtr client)
swapl(&stuff->time, n);
swaps(&stuff->event_count, n);
- if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count)
+ if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count)
return BadLength;
SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count);
@@ -110,7 +110,7 @@ ProcXGrabDevice(ClientPtr client)
REQUEST(xGrabDeviceReq);
REQUEST_AT_LEAST_SIZE(xGrabDeviceReq);
- if (stuff->length != (sizeof(xGrabDeviceReq) >> 2) + stuff->event_count)
+ if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count)
return BadLength;
rep.repType = X_Reply;
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 58fb73b..e235f53 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -110,7 +110,7 @@ ProcXGrabDeviceButton(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xGrabDeviceButtonReq);
if (stuff->length !=
- (sizeof(xGrabDeviceButtonReq) >> 2) + stuff->event_count)
+ bytes_to_int32(sizeof(xGrabDeviceButtonReq)) + stuff->event_count)
return BadLength;
ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index 9ae38f0..b34867b 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -107,7 +107,7 @@ ProcXGrabDeviceKey(ClientPtr client)
REQUEST(xGrabDeviceKeyReq);
REQUEST_AT_LEAST_SIZE(xGrabDeviceKeyReq);
- if (stuff->length != (sizeof(xGrabDeviceKeyReq) >> 2) + stuff->event_count)
+ if (stuff->length != bytes_to_int32(sizeof(xGrabDeviceKeyReq)) + stuff->event_count)
return BadLength;
ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 55d45a3..8e91c5a 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -136,7 +136,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
(ScreenPtr) NULL, FALSE);
}
if (rep.nEvents > 0) {
- length = (rep.nEvents * size + 3) >> 2;
+ length = bytes_to_int32(rep.nEvents * size);
rep.length = length;
}
nEvents = rep.nEvents;
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 1c847fb..563fc07 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -409,7 +409,7 @@ ProcXListInputDevices(ClientPtr client)
ListDeviceInfo(client, d, dev++, &devbuf, &classbuf, &namebuf);
}
rep.ndevices = numdevs;
- rep.length = (total_length + 3) >> 2;
+ rep.length = bytes_to_int32(total_length);
WriteReplyToClient(client, sizeof(xListInputDevicesReply), &rep);
WriteToClient(client, total_length, savbuf);
xfree(savbuf);
diff --git a/Xi/opendev.c b/Xi/opendev.c
index 46d55a8..3844d25 100644
--- a/Xi/opendev.c
+++ b/Xi/opendev.c
@@ -150,7 +150,7 @@ ProcXOpenDevice(ClientPtr client)
}
evbase[j].class = OtherClass;
evbase[j++].event_type_base = event_base[OtherClass];
- rep.length = (j * sizeof(xInputClassInfo) + 3) >> 2;
+ rep.length = bytes_to_int32(j * sizeof(xInputClassInfo));
rep.num_classes = j;
WriteReplyToClient(client, sizeof(xOpenDeviceReply), &rep);
WriteToClient(client, j * sizeof(xInputClassInfo), (char *)evbase);
diff --git a/Xi/queryst.c b/Xi/queryst.c
index c6858e4..60ec32e 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -161,7 +161,7 @@ ProcXQueryDeviceState(ClientPtr client)
}
rep.num_classes = num_classes;
- rep.length = (total_length + 3) >> 2;
+ rep.length = bytes_to_int32(total_length);
WriteReplyToClient(client, sizeof(xQueryDeviceStateReply), &rep);
if (total_length > 0)
WriteToClient(client, total_length, savbuf);
diff --git a/Xi/selectev.c b/Xi/selectev.c
index 013fdc9..031e602 100644
--- a/Xi/selectev.c
+++ b/Xi/selectev.c
@@ -154,7 +154,7 @@ ProcXSelectExtensionEvent(ClientPtr client)
REQUEST(xSelectExtensionEventReq);
REQUEST_AT_LEAST_SIZE(xSelectExtensionEventReq);
- if (stuff->length != (sizeof(xSelectExtensionEventReq) >> 2) + stuff->count)
+ if (stuff->length != bytes_to_int32(sizeof(xSelectExtensionEventReq)) + stuff->count)
return BadLength;
ret = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
diff --git a/Xi/sendexev.c b/Xi/sendexev.c
index 63b45ee..8629dd2 100644
--- a/Xi/sendexev.c
+++ b/Xi/sendexev.c
@@ -89,8 +89,8 @@ SProcXSendExtensionEvent(ClientPtr client)
swapl(&stuff->destination, n);
swaps(&stuff->count, n);
- if (stuff->length != (sizeof(xSendExtensionEventReq) >> 2) + stuff->count +
- (stuff->num_events * (sizeof(xEvent) >> 2)))
+ if (stuff->length != bytes_to_int32(sizeof(xSendExtensionEventReq)) + stuff->count +
+ bytes_to_int32(stuff->num_events * sizeof(xEvent)))
return BadLength;
eventP = (xEvent *) & stuff[1];
@@ -126,8 +126,8 @@ ProcXSendExtensionEvent(ClientPtr client)
REQUEST(xSendExtensionEventReq);
REQUEST_AT_LEAST_SIZE(xSendExtensionEventReq);
- if (stuff->length != (sizeof(xSendExtensionEventReq) >> 2) + stuff->count +
- (stuff->num_events * (sizeof(xEvent) >> 2)))
+ if (stuff->length != bytes_to_int32(sizeof(xSendExtensionEventReq)) + stuff->count +
+ (stuff->num_events * bytes_to_int32(sizeof(xEvent))))
return BadLength;
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixWriteAccess);
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index e7b8d4a..37c40e4 100644
--- a/Xi/setbmap.c
+++ b/Xi/setbmap.c
@@ -94,8 +94,8 @@ ProcXSetDeviceButtonMapping(ClientPtr client)
REQUEST(xSetDeviceButtonMappingReq);
REQUEST_AT_LEAST_SIZE(xSetDeviceButtonMappingReq);
- if (stuff->length != (sizeof(xSetDeviceButtonMappingReq) +
- stuff->map_length + 3) >> 2)
+ if (stuff->length !=
+ bytes_to_int32(sizeof(xSetDeviceButtonMappingReq) + stuff->map_length))
return BadLength;
ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
diff --git a/Xi/setdval.c b/Xi/setdval.c
index fe5f316..b384f0d 100644
--- a/Xi/setdval.c
+++ b/Xi/setdval.c
@@ -100,7 +100,7 @@ ProcXSetDeviceValuators(ClientPtr client)
rep.status = Success;
rep.sequenceNumber = client->sequence;
- if (stuff->length != (sizeof(xSetDeviceValuatorsReq) >> 2) +
+ if (stuff->length != bytes_to_int32(sizeof(xSetDeviceValuatorsReq)) +
stuff->num_valuators)
return BadLength;
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index ffcc7f3..cbe5dc8 100644
--- a/Xi/setmmap.c
+++ b/Xi/setmmap.c
@@ -96,8 +96,8 @@ ProcXSetDeviceModifierMapping(ClientPtr client)
REQUEST(xSetDeviceModifierMappingReq);
REQUEST_AT_LEAST_SIZE(xSetDeviceModifierMappingReq);
- if (stuff->length != ((sizeof(xSetDeviceModifierMappingReq) >> 2) +
- (stuff->numKeyPerModifier << 1)))
+ if (stuff->length != bytes_to_int32(sizeof(xSetDeviceModifierMappingReq)) +
+ (stuff->numKeyPerModifier << 1))
return BadLength;
rep.repType = X_Reply;
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 656515b..9f52b6d 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -112,7 +112,7 @@ void XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
}
}
- ev->length = (ev->num_info * sizeof(xXIHierarchyInfo))/4;
+ ev->length = bytes_to_int32(ev->num_info * sizeof(xXIHierarchyInfo));
dummyDev.id = XIAllDevices;
SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1);
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 55f20c4..0a47e31 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -903,7 +903,7 @@ ProcXChangeDeviceProperty (ClientPtr client)
stuff->format, stuff->mode, stuff->nUnits);
len = stuff->nUnits;
- if (len > ((0xffffffff - sizeof(xChangeDevicePropertyReq)) >> 2))
+ if (len > (bytes_to_int32(0xffffffff - sizeof(xChangeDevicePropertyReq))))
return BadLength;
totalSize = len * (stuff->format/8);
@@ -972,7 +972,7 @@ ProcXGetDeviceProperty (ClientPtr client)
reply.format = format;
reply.bytesAfter = bytes_after;
reply.propertyType = type;
- reply.length = (length + 3) >> 2;
+ reply.length = bytes_to_int32(length);
if (stuff->delete && (reply.bytesAfter == 0))
send_property_event(dev, stuff->property, XIPropertyDeleted);
@@ -1146,7 +1146,7 @@ ProcXIChangeProperty(ClientPtr client)
rc = check_change_property(client, stuff->property, stuff->type,
stuff->format, stuff->mode, stuff->num_items);
len = stuff->num_items;
- if (len > ((0xffffffff - sizeof(xXIChangePropertyReq)) >> 2))
+ if (len > bytes_to_int32(0xffffffff - sizeof(xXIChangePropertyReq)))
return BadLength;
totalSize = len * (stuff->format/8);
@@ -1215,7 +1215,7 @@ ProcXIGetProperty(ClientPtr client)
reply.format = format;
reply.bytes_after = bytes_after;
reply.type = type;
- reply.length = (length + 3)/4;
+ reply.length = bytes_to_int32(length);
if (length && stuff->delete && (reply.bytes_after == 0))
send_property_event(dev, stuff->property, XIPropertyDeleted);
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 33628a6..68d91fa 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -200,7 +200,7 @@ SizeDeviceInfo(DeviceIntPtr dev)
int len = sizeof(xXIDeviceInfo);
/* 4-padded name */
- len += (((strlen(dev->name) + 3)/4)*4);
+ len += pad_to_int32(strlen(dev->name));
return len + SizeDeviceClasses(dev);
@@ -218,7 +218,7 @@ SizeDeviceClasses(DeviceIntPtr dev)
{
len += sizeof(xXIButtonInfo);
len += dev->button->numButtons * sizeof(Atom);
- len += ((((dev->button->numButtons + 7)/8) + 3)/4) * 4;
+ len += pad_to_int32(bits_to_bytes(dev->button->numButtons));
}
if (dev->key)
@@ -246,11 +246,12 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
int mask_len;
int i;
- mask_len = (((dev->button->numButtons + 7)/8) + 3)/4; /* 4-byte units*/
+ mask_len = bytes_to_int32(bits_to_bytes(dev->button->numButtons));
info->type = ButtonClass;
info->num_buttons = dev->button->numButtons;
- info->length = sizeof(xXIButtonInfo)/4 + mask_len + info->num_buttons;
+ info->length = bytes_to_int32(sizeof(xXIButtonInfo)) +
+ info->num_buttons + mask_len;
info->sourceid = dev->button->sourceid;
bits = (unsigned char*)&info[1];
@@ -400,7 +401,7 @@ ListDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
info->enabled = dev->enabled;
total_len = sizeof(xXIDeviceInfo);
- len = ((info->name_len + 3)/4) * 4;
+ len = pad_to_int32(info->name_len);
memset(any, 0, len);
strncpy(any, dev->name, info->name_len);
any += len;
@@ -456,7 +457,7 @@ SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
int i;
/* Skip over name */
- any += (((info->name_len + 3)/4) * 4);
+ any += pad_to_int32(info->name_len);
for (i = 0; i < info->num_classes; i++)
{
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index 2222873..da1d101 100644
--- a/Xi/xiquerypointer.c
+++ b/Xi/xiquerypointer.c
@@ -126,7 +126,7 @@ ProcXIQueryPointer(ClientPtr client)
if (pDev->button)
{
int i, down;
- rep.buttons_len = (((pDev->button->numButtons + 7)/8) + 3)/4;
+ rep.buttons_len = bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
rep.length += rep.buttons_len;
buttons = xcalloc(rep.buttons_len, 4);
if (!buttons)
diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index 750ae61..2baae77 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -196,7 +196,7 @@ ProcXIGetSelectedEvents(ClientPtr client)
return Success;
}
- buffer = xcalloc(MAXDEVICES, sizeof(xXIEventMask) + ((XI2MASKSIZE + 3)/4) * 4);
+ buffer = xcalloc(MAXDEVICES, sizeof(xXIEventMask) + pad_to_int32(XI2MASKSIZE));
if (!buffer)
return BadAlloc;
commit 912402fd71144bcee255141efe12a78abad39240
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date: Mon Jun 29 13:09:57 2009 +1000
include: introduce byte counting functions.
This patch adds the following three functions:
bits_to_bytes(bits) - the number of bytes needed to hold 'bits'
bytes_to_int32(bytes) - the number of 4-byte units to hold 'bytes'
pad_to_int32(bytes) - the closest multiple of 4 equal to or larger than
'bytes'.
All three operations are common in protocol processing and currently the
server has ((foo + 7)/8 + 3)/4 operations all over the place. A common set
of functions reduce the error rate of these (albeit simple) calculations and
improve readability of the code.
The functions do not check for overflow.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
diff --git a/include/misc.h b/include/misc.h
index 61dd947..877c682 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -180,6 +180,36 @@ typedef struct _xReq *xReqPtr;
#endif
+/**
+ * Calculate the number of bytes needed to hold bits.
+ * @param bits The minimum number of bits needed.
+ * @return The number of bytes needed to hold bits.
+ */
+static inline int
+bits_to_bytes(const int bits) {
+ return ((bits + 7) >> 3);
+}
+/**
+ * Calculate the number of 4-byte units needed to hold the given number of
+ * bytes.
+ * @param bytes The minimum number of bytes needed.
+ * @return The number of 4-byte units needed to hold bytes.
+ */
+static inline int
+bytes_to_int32(const int bytes) {
+ return (((bytes) + 3) >> 2);
+}
+
+/**
+ * Calculate the number of bytes (in multiples of 4) needed to hold bytes.
+ * @param bytes The minimum number of bytes needed.
+ * @return The closest multiple of 4 that is equal or higher than bytes.
+ */
+static inline int
+pad_to_int32(const int bytes) {
+ return (((bytes) + 3) & ~3);
+}
+
/* some macros to help swap requests, replies, and events */
#define LengthRestB(stuff) \
diff --git a/test/input.c b/test/input.c
index bb32491..e2faaef 100644
--- a/test/input.c
+++ b/test/input.c
@@ -678,6 +678,44 @@ static void dix_grab_matching(void)
g_assert(rc == TRUE);
}
+static void include_byte_padding_macros(void)
+{
+ int i;
+ g_test_message("Testing bits_to_bytes()");
+
+ /* the macros don't provide overflow protection */
+ for (i = 0; i < INT_MAX - 7; i++)
+ {
+ int expected_bytes;
+ expected_bytes = (i + 7)/8;
+
+ g_assert(bits_to_bytes(i) >= i/8);
+ g_assert((bits_to_bytes(i) * 8) - i <= 7);
+ }
+
+ g_test_message("Testing bytes_to_int32()");
+ for (i = 0; i < INT_MAX - 3; i++)
+ {
+ int expected_4byte;
+ expected_4byte = (i + 3)/4;
+
+ g_assert(bytes_to_int32(i) <= i);
+ g_assert((bytes_to_int32(i) * 4) - i <= 3);
+ }
+
+ g_test_message("Testing pad_to_int32");
+
+ for (i = 0; i < INT_MAX - 3; i++)
+ {
+ int expected_bytes;
+ expected_bytes = ((i + 3)/4) * 4;
+
+ g_assert(pad_to_int32(i) >= i);
+ g_assert(pad_to_int32(i) - i <= 3);
+ }
+
+}
+
int main(int argc, char** argv)
{
g_test_init(&argc, &argv,NULL);
@@ -688,6 +726,7 @@ int main(int argc, char** argv)
g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
+ g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
return g_test_run();
}
More information about the xorg-commit
mailing list