[PATCH 02/18] Xi: use byte-counting macros instead of manual calculation.

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


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

diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index 89e5a2d..b823b2a 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 - num_dwords_for_bytes(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 < num_dwords_for_bytes(sizeof(xDeviceResolutionCtl))) ||
+	    (len != num_dwords_for_bytes(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) {
             ret = BadLength;
             goto out;
 	}
diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index e193e13..db4e08b 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 - num_dwords_for_bytes(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 != num_dwords_for_bytes(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 != num_dwords_for_bytes(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 != (num_dwords_for_bytes(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 != num_dwords_for_bytes(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 != num_dwords_for_bytes(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 != num_dwords_for_bytes(sizeof(xBellFeedbackCtl)))
 	    return BadLength;
 
 	for (b = dev->bell; b; b = b->next)
diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
index 854c17f..d7aded2 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 - num_dwords_for_bytes(sizeof(xChangeDeviceKeyMappingReq));
 
     ret = ChangeKeyMapping(client, dev, len, DeviceMappingNotify,
 			   stuff->firstKeyCode, stuff->keyCodes,
diff --git a/Xi/chgprop.c b/Xi/chgprop.c
index d8e37a7..bb3fe48 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 != num_dwords_for_bytes(sizeof(xChangeDeviceDontPropagateListReq)) +
 	stuff->count)
 	return BadLength;
 
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 34fdf50..5ccdd5b 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_dwords(num_bytes_for_bits(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 = num_dwords_for_bytes(len - sizeof(xEvent));
 
     ptr = (char*)&dcce[1];
     if (dce->buttons.num_buttons)
@@ -1247,15 +1247,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) ? num_bytes_for_bits(mouse->button->numButtons) : 0;
+    btlen = num_dwords_for_bytes(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       = num_dwords_for_bytes(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..b18ff57 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 = num_dwords_for_bytes(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..ba8e663 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 = num_dwords_for_bytes(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..76b26a9 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 = num_dwords_for_bytes(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..d2197de 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 = num_dwords_for_bytes(rep.count * sizeof(XEventClass));
 
 	    tbuf = buf;
 	    for (i = 0; i < EMASKSIZE; i++)
diff --git a/Xi/getselev.c b/Xi/getselev.c
index ea9bd9b..75a229d 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 = num_dwords_for_bytes(total_length);
 	buf = (XEventClass *) xalloc(total_length);
 
 	tclient = buf;
diff --git a/Xi/getvers.c b/Xi/getvers.c
index c8eacc1..76a9a56 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 != num_dwords_for_bytes(sizeof(xGetExtensionVersionReq) +
+			  stuff->nbytes))
 	return BadLength;
 
     memset(&rep, 0, sizeof(xGetExtensionVersionReply));
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index e1d430a..1944b78 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 != num_dwords_for_bytes(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 != num_dwords_for_bytes(sizeof(xGrabDeviceReq)) + stuff->event_count)
 	return BadLength;
 
     rep.repType = X_Reply;
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 58fb73b..8bceb84 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)
+	num_dwords_for_bytes(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..f2d6717 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 != num_dwords_for_bytes(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..3528d8d 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 = num_dwords_for_bytes(rep.nEvents * size);
 	rep.length = length;
     }
     nEvents = rep.nEvents;
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 1c847fb..59745bd 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 = num_dwords_for_bytes(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..761bc88 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 = num_dwords_for_bytes(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..86a3590 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 = num_dwords_for_bytes(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..7ee9f26 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 != num_dwords_for_bytes(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..2565e44 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 != num_dwords_for_bytes(sizeof(xSendExtensionEventReq)) + stuff->count +
+       num_dwords_for_bytes(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 != num_dwords_for_bytes(sizeof(xSendExtensionEventReq)) + stuff->count +
+	(stuff->num_events * num_dwords_for_bytes(sizeof(xEvent))))
 	return BadLength;
 
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixWriteAccess);
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index e7b8d4a..2c4cdb4 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 !=
+        num_dwords_for_bytes(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..927904a 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 != num_dwords_for_bytes(sizeof(xSetDeviceValuatorsReq)) +
 	stuff->num_valuators)
 	return BadLength;
 
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index ffcc7f3..220b35b 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 != num_dwords_for_bytes(sizeof(xSetDeviceModifierMappingReq)) +
+                          (stuff->numKeyPerModifier << 1))
         return BadLength;
 
     rep.repType = X_Reply;
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 656515b..878fefd 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 = num_dwords_for_bytes(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..c973112 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 > (num_dwords_for_bytes(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 = num_dwords_for_bytes(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 > num_dwords_for_bytes(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 = num_dwords_for_bytes(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..990d4bb 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_dwords(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_dwords(num_bytes_for_bits(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 = num_dwords_for_bytes(num_bytes_for_bits(dev->button->numButtons));
 
     info->type = ButtonClass;
     info->num_buttons = dev->button->numButtons;
-    info->length = sizeof(xXIButtonInfo)/4 + mask_len + info->num_buttons;
+    info->length = num_dwords_for_bytes(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_dwords(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_dwords(info->name_len);
 
     for (i = 0; i < info->num_classes; i++)
     {
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index 2222873..bf9512b 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 = num_dwords_for_bytes(num_bytes_for_bits(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..b688028 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_dwords(XI2MASKSIZE));
     if (!buffer)
         return BadAlloc;
 
-- 
1.6.3.rc1.2.g0164.dirty



More information about the xorg-devel mailing list