[PATCH 10/18] Xext: switch to byte counting functions

Peter Hutterer peter.hutterer at who-t.net
Wed Jul 8 17:05:08 PDT 2009


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 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 ++++----
 12 files changed, 51 insertions(+), 51 deletions(-)

diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index 09399b6..c33e8c5 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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 * num_dwords_for_bytes(sizeof (xMbufBufferInfo));
     rep.normalInfo = nInfo;
     rep.stereoInfo = 0;
     if (client->swapped)
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 4ab6f6b..af771bf 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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(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..521927d 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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 = num_dwords_for_bytes((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 = num_dwords_for_bytes((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 = num_dwords_for_bytes((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 = num_dwords_for_bytes(length);
 
     if (widthBytesLine == 0 || h == 0)
 	linesPerBuf = 0;
diff --git a/Xext/saver.c b/Xext/saver.c
index b59f769..822d6f7 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 -  num_dwords_for_bytes(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 -  num_dwords_for_bytes(sizeof(xScreenSaverSetAttributesReq));
        if (Ones(stuff->mask) != len)
            return BadLength;
 
diff --git a/Xext/security.c b/Xext/security.c
index bae95a3..5baf48f 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 = num_dwords_for_bytes(SIZEOF(xSecurityGenerateAuthorizationReq));
+    len += num_dwords_for_bytes(stuff->nbytesAuthProto);
+    len += num_dwords_for_bytes(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 + num_dwords_for_bytes(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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(stuff->nbytesAuthProto) +
+		    num_dwords_for_bytes(stuff->nbytesAuthData);
     if (values_offset > 
-	stuff->length - (sz_xSecurityGenerateAuthorizationReq >> 2))
+	stuff->length - num_dwords_for_bytes(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..2e89039 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 = num_dwords_for_bytes(nrects * sizeof (xRectangle));
     rep.ordering = YXBanded;
     rep.nrects = nrects;
     if (client->swapped) {
diff --git a/Xext/sync.c b/Xext/sync.c
index d7ab63c..4e91e10 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_dwords(sz_xSyncSystemCounter + strlen(name));
     }
 
     if (len)
@@ -1189,7 +1189,7 @@ ProcSyncListSystemCounters(ClientPtr client)
 	    return BadAlloc;
     }
 
-    rep.length = len >> 2;
+    rep.length = num_dwords_for_bytes(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_dwords(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 - num_dwords_for_bytes(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 - num_dwords_for_bytes(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 = num_dwords_for_bytes(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply));
     rep.sequenceNumber = client->sequence;
 
     pTrigger = &pAlarm->trigger;
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 7d4c697..ddefca2 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 = num_dwords_for_bytes(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..e767062 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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(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..d40f917 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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(strlen(i->octx) + 1);
+    i->dctx_len = num_dwords_for_bytes(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..e38d940 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_dwords(strlen(pa->name));
       totalSize += pa->nFormats * sz_xvFormat;
       pa++;
     }
 
-  rep.length = totalSize >> 2;
+  rep.length = num_dwords_for_bytes(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_dwords(strlen(pe->name));
       pe++;
     }
 
-  rep.length = totalSize >> 2;
+  rep.length = num_dwords_for_bytes(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_dwords(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_dwords(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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(pPort->pAdaptor->nImages * sz_xvImageFormatInfo);
 
   _WriteListImageFormatsReply(client, &rep);
 
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 879a222..8da156b 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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(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 = num_dwords_for_bytes(strlen(pScreenPriv->clientDriverName) + 1);
+    rep.busIDLen = num_dwords_for_bytes(strlen(pScreenPriv->busID) + 1);
 
     rep.length = rep.nameLen + rep.busIDLen;
     rep.nameLen <<=2;
-- 
1.6.3.rc1.2.g0164.dirty



More information about the xorg-devel mailing list