[PATCH] Return Success from generate_modkeymap() when max_keys_per_mod is zero.

Adam Tkac atkac at redhat.com
Tue Aug 24 08:21:30 PDT 2010


max_keys_per_mod equal to zero is a valid situation so generate_modkeymap
should not return BadAlloc in this case.

Signed-off-by: Adam Tkac <atkac at redhat.com>
---
 dix/inpututils.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 8ec80b5..6693c67 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -286,7 +286,7 @@ int generate_modkeymap(ClientPtr client, DeviceIntPtr dev,
 {
     CARD8 keys_per_mod[8];
     int max_keys_per_mod;
-    KeyCode *modkeymap;
+    KeyCode *modkeymap = NULL;
     int i, j, ret;
 
     ret = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixGetAttrAccess);
@@ -310,18 +310,20 @@ int generate_modkeymap(ClientPtr client, DeviceIntPtr dev,
         }
     }
 
-    modkeymap = calloc(max_keys_per_mod * 8, sizeof(KeyCode));
-    if (!modkeymap)
-        return BadAlloc;
+    if (max_keys_per_mod != 0) {
+        modkeymap = calloc(max_keys_per_mod * 8, sizeof(KeyCode));
+        if (!modkeymap)
+            return BadAlloc;
 
-    for (i = 0; i < 8; i++)
-        keys_per_mod[i] = 0;
+        for (i = 0; i < 8; i++)
+            keys_per_mod[i] = 0;
 
-    for (i = 8; i < MAP_LENGTH; i++) {
-        for (j = 0; j < 8; j++) {
-            if (dev->key->xkbInfo->desc->map->modmap[i] & (1 << j)) {
-                modkeymap[(j * max_keys_per_mod) + keys_per_mod[j]] = i;
-                keys_per_mod[j]++;
+        for (i = 8; i < MAP_LENGTH; i++) {
+            for (j = 0; j < 8; j++) {
+                if (dev->key->xkbInfo->desc->map->modmap[i] & (1 << j)) {
+                    modkeymap[(j * max_keys_per_mod) + keys_per_mod[j]] = i;
+                    keys_per_mod[j]++;
+                }
             }
         }
     }
-- 
1.7.2.2


--FCuugMFkClbJLl1L--


More information about the xorg-devel mailing list