summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xext/geext.c2
-rw-r--r--Xi/extinit.c7
-rw-r--r--Xi/xiquerydevice.c3
-rw-r--r--dix/eventconvert.c27
-rw-r--r--hw/xfree86/loader/loadmod.c6
-rw-r--r--xkb/XKBGAlloc.c64
-rw-r--r--xkb/xkbUtils.c129
-rw-r--r--xkb/xkbgeom.h20
8 files changed, 140 insertions, 118 deletions
diff --git a/Xext/geext.c b/Xext/geext.c
index b37c1a0bd..a6fbb0947 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -187,3 +187,3 @@ SGEGenericEvent(xEvent* from, xEvent* to)
- if (gefrom->extension > MAXEXTENSIONS)
+ if ((gefrom->extension & 0x7f) > MAXEXTENSIONS)
{
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 46d34599c..0b7280d95 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -51,2 +51,3 @@ SOFTWARE.
*/
+#define ARRAY_SIZE(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -412,3 +413,3 @@ ProcIDispatch(ClientPtr client)
REQUEST(xReq);
- if (stuff->data > (IREQUESTS + XI2REQUESTS) || !ProcIVector[stuff->data])
+ if (stuff->data > ARRAY_SIZE(ProcIVector) || !ProcIVector[stuff->data])
return BadRequest;
@@ -431,3 +432,3 @@ SProcIDispatch(ClientPtr client)
REQUEST(xReq);
- if (stuff->data > IREQUESTS || !SProcIVector[stuff->data])
+ if (stuff->data > ARRAY_SIZE(SProcIVector) || !SProcIVector[stuff->data])
return BadRequest;
@@ -865,2 +866,4 @@ XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
case XI_Leave:
+ case XI_FocusIn:
+ case XI_FocusOut:
SDeviceLeaveNotifyEvent((xXILeaveEvent*)from, (xXILeaveEvent*)to);
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 8b6990491..a768d499c 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -157,4 +157,5 @@ ProcXIQueryDevice(ClientPtr client)
+ len = rep.length * 4;
WriteReplyToClient(client, sizeof(xXIQueryDeviceReply), &rep);
- WriteToClient(client, rep.length * 4, ptr);
+ WriteToClient(client, len, ptr);
free(ptr);
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index c9d199436..a5fe0a9cc 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -385,2 +385,3 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv)
int first_valuator, num_valuators;
+ DeviceIntPtr dev = NULL;
@@ -390,3 +391,2 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv)
{
- DeviceIntPtr dev = NULL;
dixLookupDevice(&dev, ev->deviceid, serverClient, DixUseAccess);
@@ -397,4 +397,6 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv)
- /* FIXME: non-continuous valuator data in internal events*/
for (i = 0; i < num_valuators; i += 6, xv++) {
+ INT32 *valuators = &xv->valuator0; // Treat all 6 vals as an array
+ int j;
+
xv->type = DeviceValuator;
@@ -404,15 +406,10 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv)
xv->device_state = state;
- switch (xv->num_valuators) {
- case 6:
- xv->valuator5 = ev->valuators.data[xv->first_valuator + 5];
- case 5:
- xv->valuator4 = ev->valuators.data[xv->first_valuator + 4];
- case 4:
- xv->valuator3 = ev->valuators.data[xv->first_valuator + 3];
- case 3:
- xv->valuator2 = ev->valuators.data[xv->first_valuator + 2];
- case 2:
- xv->valuator1 = ev->valuators.data[xv->first_valuator + 1];
- case 1:
- xv->valuator0 = ev->valuators.data[xv->first_valuator + 0];
+
+ for (j = 0; j < xv->num_valuators; j++) {
+ if (BitIsOn(ev->valuators.mask, xv->first_valuator + j))
+ valuators[j] = ev->valuators.data[xv->first_valuator + j];
+ else if (dev->valuator->axes[xv->first_valuator + j].mode == Absolute)
+ valuators[j] = dev->valuator->axisVal[xv->first_valuator + j];
+ else
+ valuators[j] = 0;
}
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index eaa99e8c4..46ce68b86 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -534,2 +534,3 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
FreePatterns(patterns);
+ closedir(d);
return NULL;
@@ -542,2 +543,3 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
FreePatterns(patterns);
+ closedir(d);
return NULL;
@@ -558,2 +560,6 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
listing[n] = NULL;
+
+ FreePathList(pathlist);
+ FreeSubdirs(subdirs);
+ FreePatterns(patterns);
return listing;
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index 65f92fdba..dd2b04696 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -437,2 +437,53 @@ XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
+/**
+ * Resize and clear an XKB geometry item array. The array size may
+ * grow or shrink unlike in _XkbGeomAlloc.
+ *
+ * @param buffer[in,out] buffer to reallocate and clear
+ * @param szItems[in] currently allocated item count for "buffer"
+ * @param nrItems[in] required item count for "buffer"
+ * @param itemSize[in] size of a single item in "buffer"
+ * @param clearance[in] items to clear after reallocation
+ *
+ * @see _XkbGeomAlloc
+ *
+ * @return TRUE if reallocation succeeded. Otherwise FALSE is returned
+ * and contents of "buffer" aren't touched.
+ */
+Bool
+XkbGeomRealloc(void **buffer, int szItems, int nrItems,
+ int itemSize, XkbGeomClearance clearance)
+{
+ void *items;
+ int clearBegin;
+ /* Check validity of arguments. */
+ if (!buffer)
+ return FALSE;
+ items = *buffer;
+ if (!((items && (szItems > 0)) || (!items && !szItems)))
+ return FALSE;
+ /* Check if there is need to resize. */
+ if (nrItems != szItems)
+ if (!(items = realloc(items, nrItems * itemSize)))
+ return FALSE;
+ /* Clear specified items to zero. */
+ switch (clearance)
+ {
+ case XKB_GEOM_CLEAR_EXCESS:
+ clearBegin = szItems;
+ break;
+ case XKB_GEOM_CLEAR_ALL:
+ clearBegin = 0;
+ break;
+ case XKB_GEOM_CLEAR_NONE:
+ default:
+ clearBegin = nrItems;
+ break;
+ }
+ if (items && (clearBegin < nrItems))
+ memset((char *)items + (clearBegin * itemSize), 0, (nrItems - clearBegin) * itemSize);
+ *buffer = items;
+ return TRUE;
+}
+
static Status
@@ -453,6 +504,7 @@ _XkbGeomAlloc( void ** old,
*total= (*num)+num_new;
- if ((*old)!=NULL)
- (*old)= realloc((*old),(*total)*sz_elem);
- else (*old)= calloc((*total),sz_elem);
- if ((*old)==NULL) {
+
+ if (!XkbGeomRealloc(old, *num, *total, sz_elem, XKB_GEOM_CLEAR_EXCESS))
+ {
+ free(*old);
+ (*old)= NULL;
*total= *num= 0;
@@ -461,6 +513,2 @@ _XkbGeomAlloc( void ** old,
- if (*num>0) {
- char *tmp= (char *)(*old);
- memset(&tmp[sz_elem*(*num)], 0, (num_new*sz_elem));
- }
return Success;
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 3a56bea4c..cc9aaa75a 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1400,28 +1400,18 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_properties) {
- if (src->geom->num_properties != dst->geom->sz_properties) {
- /* If we've got more properties in the destination than
- * the source, run through and free all the excess ones
- * first. */
- if (src->geom->num_properties < dst->geom->sz_properties) {
- for (i = src->geom->num_properties,
- dprop = dst->geom->properties + i;
- i < dst->geom->num_properties;
- i++, dprop++) {
- free(dprop->name);
- free(dprop->value);
- }
+ /* If we've got more properties in the destination than
+ * the source, run through and free all the excess ones
+ * first. */
+ if (src->geom->num_properties < dst->geom->sz_properties) {
+ for (i = src->geom->num_properties, dprop = dst->geom->properties + i;
+ i < dst->geom->num_properties;
+ i++, dprop++) {
+ free(dprop->name);
+ free(dprop->value);
}
-
- if (dst->geom->sz_properties)
- tmp = realloc(dst->geom->properties,
- src->geom->num_properties *
- sizeof(XkbPropertyRec));
- else
- tmp = malloc(src->geom->num_properties *
- sizeof(XkbPropertyRec));
- if (!tmp)
- return FALSE;
- dst->geom->properties = tmp;
}
+ /* Reallocate and clear all new items if the buffer grows. */
+ if (!XkbGeomRealloc((void **)&dst->geom->properties, dst->geom->sz_properties, src->geom->num_properties,
+ sizeof(XkbPropertyRec), XKB_GEOM_CLEAR_EXCESS))
+ return FALSE;
/* We don't set num_properties as we need it to try and avoid
@@ -1430,8 +1420,2 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
- if (dst->geom->sz_properties > dst->geom->num_properties) {
- memset(dst->geom->properties + dst->geom->num_properties, 0,
- (dst->geom->sz_properties - dst->geom->num_properties) *
- sizeof(XkbPropertyRec));
- }
-
for (i = 0,
@@ -1484,32 +1468,16 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_colors) {
- if (src->geom->num_colors != dst->geom->sz_colors) {
- if (src->geom->num_colors < dst->geom->sz_colors) {
- for (i = src->geom->num_colors,
- dcolor = dst->geom->colors + i;
- i < dst->geom->num_colors;
- i++, dcolor++) {
- free(dcolor->spec);
- }
+ if (src->geom->num_colors < dst->geom->sz_colors) {
+ for (i = src->geom->num_colors, dcolor = dst->geom->colors + i;
+ i < dst->geom->num_colors;
+ i++, dcolor++) {
+ free(dcolor->spec);
}
-
- if (dst->geom->sz_colors)
- tmp = realloc(dst->geom->colors,
- src->geom->num_colors *
- sizeof(XkbColorRec));
- else
- tmp = malloc(src->geom->num_colors *
- sizeof(XkbColorRec));
- if (!tmp)
- return FALSE;
- dst->geom->colors = tmp;
}
+ /* Reallocate and clear all new items if the buffer grows. */
+ if (!XkbGeomRealloc((void **)&dst->geom->colors, dst->geom->sz_colors, src->geom->num_colors,
+ sizeof(XkbColorRec), XKB_GEOM_CLEAR_EXCESS))
+ return FALSE;
dst->geom->sz_colors = src->geom->num_colors;
- if (dst->geom->sz_colors > dst->geom->num_colors) {
- memset(dst->geom->colors + dst->geom->num_colors, 0,
- (dst->geom->sz_colors - dst->geom->num_colors) *
- sizeof(XkbColorRec));
- }
-
for (i = 0,
@@ -1575,6 +1543,6 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_shapes) {
- tmp = calloc(src->geom->num_shapes, sizeof(XkbShapeRec));
- if (!tmp)
+ /* Reallocate and clear all items. */
+ if (!XkbGeomRealloc((void **)&dst->geom->shapes, dst->geom->sz_shapes, src->geom->num_shapes,
+ sizeof(XkbShapeRec), XKB_GEOM_CLEAR_ALL))
return FALSE;
- dst->geom->shapes = tmp;
@@ -1695,3 +1663,2 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
dst->geom->num_sections = 0;
- dst->geom->sections = NULL;
}
@@ -1699,12 +1666,6 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_sections) {
- if (dst->geom->sz_sections)
- tmp = realloc(dst->geom->sections,
- src->geom->num_sections *
- sizeof(XkbSectionRec));
- else
- tmp = malloc(src->geom->num_sections * sizeof(XkbSectionRec));
- if (!tmp)
+ /* Reallocate and clear all items. */
+ if (!XkbGeomRealloc((void **)&dst->geom->sections, dst->geom->sz_sections, src->geom->num_sections,
+ sizeof(XkbSectionRec), XKB_GEOM_CLEAR_ALL))
return FALSE;
- memset(tmp, 0, src->geom->num_sections * sizeof(XkbSectionRec));
- dst->geom->sections = tmp;
dst->geom->num_sections = src->geom->num_sections;
@@ -1811,3 +1772,2 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
dst->geom->num_doodads = 0;
- dst->geom->doodads = NULL;
}
@@ -1815,13 +1775,6 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_doodads) {
- if (dst->geom->sz_doodads)
- tmp = realloc(dst->geom->doodads,
- src->geom->num_doodads *
- sizeof(XkbDoodadRec));
- else
- tmp = malloc(src->geom->num_doodads *
- sizeof(XkbDoodadRec));
- if (!tmp)
+ /* Reallocate and clear all items. */
+ if (!XkbGeomRealloc((void **)&dst->geom->doodads, dst->geom->sz_doodads, src->geom->num_doodads,
+ sizeof(XkbDoodadRec), XKB_GEOM_CLEAR_ALL))
return FALSE;
- memset(tmp, 0, src->geom->num_doodads * sizeof(XkbDoodadRec));
- dst->geom->doodads = tmp;
@@ -1862,16 +1815,10 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
if (src->geom->num_key_aliases) {
- if (src->geom->num_key_aliases != dst->geom->sz_key_aliases) {
- if (dst->geom->sz_key_aliases)
- tmp = realloc(dst->geom->key_aliases,
- src->geom->num_key_aliases *
- 2 * XkbKeyNameLength);
- else
- tmp = malloc(src->geom->num_key_aliases *
- 2 * XkbKeyNameLength);
- if (!tmp)
- return FALSE;
- dst->geom->key_aliases = tmp;
+ /* Reallocate but don't clear any items. There is no need
+ * to clear anything because data is immediately copied
+ * over the whole memory area with memcpy. */
+ if (!XkbGeomRealloc((void **)&dst->geom->key_aliases, dst->geom->sz_key_aliases, src->geom->num_key_aliases,
+ 2 * XkbKeyNameLength, XKB_GEOM_CLEAR_NONE))
+ return FALSE;
- dst->geom->sz_key_aliases = src->geom->num_key_aliases;
- }
+ dst->geom->sz_key_aliases = src->geom->num_key_aliases;
diff --git a/xkb/xkbgeom.h b/xkb/xkbgeom.h
index fe4da3806..d10b956a6 100644
--- a/xkb/xkbgeom.h
+++ b/xkb/xkbgeom.h
@@ -313,2 +313,13 @@ typedef struct _XkbGeometrySizes {
+/**
+ * Specifies which items should be cleared in an XKB geometry array
+ * when the array is reallocated.
+ */
+typedef enum
+{
+ XKB_GEOM_CLEAR_NONE, /* Don't clear any items, just reallocate. */
+ XKB_GEOM_CLEAR_EXCESS, /* Clear new extra items after reallocation. */
+ XKB_GEOM_CLEAR_ALL /* Clear all items after reallocation. */
+} XkbGeomClearance;
+
extern XkbPropertyPtr
@@ -509,2 +520,11 @@ XkbFreeGeometry(
+extern Bool
+XkbGeomRealloc(
+ void ** /* buffer */,
+ int /* szItems */,
+ int /* nrItems */,
+ int /* itemSize */,
+ XkbGeomClearance /* clearance */
+);
+
extern Status