Hi,

i think there are a few things wrong in XkbGetCoreMap. It looks like
there is some code that was duplicated(judging from a hanging xserver
and the predecessor function), an off-by-one in the size calculation and
some uninitilized members of the KeySymsRec. I am not sure about the
latter, but if these members should not be set, they probably should be
removed from KeySymsRec.

Patch attached.

Regards,
  Pierre

commit df98656dadd0766913ce7fa51ca436796b112bad
Author: Pierre Willenbrock <[email protected]>
Date:   Wed Jan 28 22:18:50 2009 +0100

    Fix duplicate code, off-by one in space calculation, not initialized members

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index c24b303..3a8d129 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -425,8 +425,10 @@ int			maxNumberOfGroups;
         maxSymsPerKey = maxNumberOfGroups * maxGroup1Width;
 
     syms->mapWidth = maxSymsPerKey;
+    syms->minKeyCode = xkb->min_key_code;
+    syms->maxKeyCode = xkb->max_key_code;
 
-    tmp = syms->mapWidth * (xkb->max_key_code - xkb->min_key_code);
+    tmp = syms->mapWidth * (xkb->max_key_code - xkb->min_key_code + 1);
     syms->map = xcalloc(tmp, sizeof(*syms->map));
     if (!syms->map) {
         xfree(syms);
@@ -458,7 +460,7 @@ int			maxNumberOfGroups;
 	 */
 	if (nGroups == 1)
 	{
-	    int idx;
+	    int idx, j;
 
 	    groupWidth = XkbKeyGroupWidth(xkb, key, XkbGroup1Index);
 
@@ -473,39 +475,16 @@ int			maxNumberOfGroups;
 	    while (groupWidth > 2 && idx < syms->mapWidth &&
 		   idx < groupWidth * 2)
 	    {
-		int idx, j;
-
-		groupWidth = XkbKeyGroupWidth(xkb, key, XkbGroup1Index);
-
-		/* AB..CDE... -> ABABCDE... */
-		if (groupWidth > 0 && maxSymsPerKey >= 3)
-		    pCore[2] = pCore[0];
-		if (groupWidth > 1 && maxSymsPerKey >= 4)
-		    pCore[3] = pCore[1];
-
-		/* ABABCDE... -> ABABCDECDE */
-		idx = 2 + groupWidth;
-		while (groupWidth > 2 &&
-			idx < maxSymsPerKey &&
-			idx < groupWidth * 2)
-		{
-		    pCore[idx] = pCore[idx - groupWidth + 2];
-		    idx++;
-		}
-		idx = 2 * groupWidth;
-		if (idx < 4)
-		    idx = 4;
-		/* 3 or more groups: ABABCDECDEABCDEABCDE */
-                for (j = 3; j <= maxNumberOfGroups; j++)
-                    for (n = 0; n < groupWidth && idx < maxSymsPerKey; n++)
-                        pCore[idx++] = pXKB[n];
+		pCore[idx] = pCore[idx - groupWidth + 2];
+		idx++;
 	    }
 	    idx = 2 * groupWidth;
 	    if (idx < 4)
 		idx = 4;
 	    /* 3 or more groups: ABABCDECDEABCDEABCDE */
-	    for (n = 0; n < groupWidth && idx < syms->mapWidth; n++)
-		pCore[idx++] = pXKB[n];
+	    for (j = 3; j <= maxNumberOfGroups; j++)
+		for (n = 0; n < groupWidth && idx < maxSymsPerKey; n++)
+		    pCore[idx++] = pXKB[n];
 	}
 
 	pXKB+= XkbKeyGroupsWidth(xkb,key);

_______________________________________________
xorg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xorg

Reply via email to