Xi: Only alloc modifierKeyMap if <slave device>->maxKeysPerModifier > 0

Sometimes (e.g. on my debian ppc box) maxKeysPerModifier of the SD is 0. So we
try to malloc(0), bringing the whole server down with a FatalError because it
looks as if the malloc failed. This is bad, so only alloc if we actually have
something to alloc.
This commit is contained in:
Peter Hutterer 2007-11-15 17:41:07 +10:30
parent 070195dbf8
commit 83926cb8be

View File

@ -147,11 +147,14 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
if (master->devPrivates[CoreDevicePrivatesIndex].ptr != device) {
memcpy(mk->modifierMap, dk->modifierMap, MAP_LENGTH);
mk->modifierKeyMap = xcalloc(8, dk->maxKeysPerModifier);
if (!mk->modifierKeyMap)
FatalError("[Xi] no memory for class shift.\n");
memcpy(mk->modifierKeyMap, dk->modifierKeyMap,
(8 * dk->maxKeysPerModifier));
if (dk->maxKeysPerModifier)
{
mk->modifierKeyMap = xcalloc(8, dk->maxKeysPerModifier);
if (!mk->modifierKeyMap)
FatalError("[Xi] no memory for class shift.\n");
memcpy(mk->modifierKeyMap, dk->modifierKeyMap,
(8 * dk->maxKeysPerModifier));
}
mk->maxKeysPerModifier = dk->maxKeysPerModifier;
mk->curKeySyms.minKeyCode = dk->curKeySyms.minKeyCode;