dix: Make EnqueueEvent aware of GenericEvents.

GenericEvents can be > sizeof(xEvents), so we need to make sure we're
allocating and copying enough memory for the event.
This commit is contained in:
Peter Hutterer 2007-09-12 18:00:03 +09:30
parent 8840829ab9
commit 06188ce90d

View File

@ -1125,13 +1125,19 @@ NoticeEventTime(xEvent *xE)
* The following procedures deal with synchronous events * * The following procedures deal with synchronous events *
**************************************************************************/ **************************************************************************/
/**
* EnqueueEvent is a device's processInputProc if a device is frozen.
* Instead of delivering the events to the client, the event is tacked onto a
* linked list for later delivery.
*/
void void
EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count) EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count)
{ {
QdEventPtr tail = *syncEvents.pendtail; QdEventPtr tail = *syncEvents.pendtail;
QdEventPtr qe; QdEventPtr qe;
xEvent *qxE; SpritePtr pSprite = device->spriteInfo->sprite;
SpritePtr pSprite = device->spriteInfo->sprite; int eventlen;
NoticeTime(xE); NoticeTime(xE);
@ -1186,7 +1192,12 @@ EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count)
return; return;
} }
} }
qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + (count * sizeof(xEvent)));
eventlen = count * sizeof(xEvent);
if (xE->u.u.type == GenericEvent) /* count is 1 for GenericEvents */
eventlen += ((xGenericEvent*)xE)->length * 4;
qe = (QdEventPtr)xalloc(sizeof(QdEventRec) + eventlen);
if (!qe) if (!qe)
return; return;
qe->next = (QdEventPtr)NULL; qe->next = (QdEventPtr)NULL;
@ -1195,8 +1206,17 @@ EnqueueEvent(xEvent *xE, DeviceIntPtr device, int count)
qe->months = currentTime.months; qe->months = currentTime.months;
qe->event = (xEvent *)(qe + 1); qe->event = (xEvent *)(qe + 1);
qe->evcount = count; qe->evcount = count;
for (qxE = qe->event; --count >= 0; qxE++, xE++) if (xE->u.u.type == GenericEvent)
*qxE = *xE; {
memcpy(qe->event, xE, eventlen);
} else
{
xEvent *qxE;
for (qxE = qe->event; --count >= 0; qxE++, xE++)
{
*qxE = *xE;
}
}
if (tail) if (tail)
syncEvents.pendtail = &tail->next; syncEvents.pendtail = &tail->next;
*syncEvents.pendtail = qe; *syncEvents.pendtail = qe;