Commit 5200132f4d11e01e7d1e9ae6439f8c5ce8bd1e9e

Ran Benita 2012-05-13T23:13:10

Revert "Fix KeyInfo's syms array size calculation" This partly reverts commit 8feba630fa7a4b720c42a9b5b4e4280b0e17a500. This seems to fix valgrind errors: ==9581== Invalid read of size 4 ==9581== at 0x4E50928: MergeKeyGroups (symbols.c:544) ==9581== by 0x4E510F3: MergeKeys (symbols.c:644) ==9581== by 0x4E514C6: AddKeySymbols (symbols.c:722) ==9581== by 0x4E51A3F: MergeIncludedSymbols (symbols.c:854) ==9581== by 0x4E51E97: HandleIncludeSymbols (symbols.c:952) ==9581== by 0x4E53D75: HandleSymbolsFile (symbols.c:1619) ==9581== by 0x4E55A0B: CompileSymbols (symbols.c:2187) ==9581== by 0x4E4056C: CompileKeymap (keymap.c:160) ==9581== by 0x4E56953: compile_keymap (xkbcomp.c:149) ==9581== by 0x4E56AC5: xkb_map_new_from_kccgst (xkbcomp.c:195) ==9581== by 0x4009D7: test_names (namescomp.c:56) ==9581== by 0x400A55: main (namescomp.c:75) ==9581== Address 0x5729b04 is 0 bytes after a block of size 4 alloc'd ==9581== at 0x4C29024: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==9581== by 0x4E5C37B: recalloc (utils.c:41) ==9581== by 0x4E4FF50: ResizeKeyGroup (symbols.c:356) ==9581== by 0x4E5229E: AddSymbolsToKey (symbols.c:1058) ==9581== by 0x4E52ABB: SetSymbolsField (symbols.c:1214) ==9581== by 0x4E536C7: HandleSymbolsBody (symbols.c:1481) ==9581== by 0x4E53A63: HandleSymbolsDef (symbols.c:1543) ==9581== by 0x4E53DAD: HandleSymbolsFile (symbols.c:1623) ==9581== by 0x4E51CA4: HandleIncludeSymbols (symbols.c:909) ==9581== by 0x4E53D75: HandleSymbolsFile (symbols.c:1619) ==9581== by 0x4E51E74: HandleIncludeSymbols (symbols.c:951) ==9581== by 0x4E53D75: HandleSymbolsFile (symbols.c:1619) Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index d342123..834ae6d 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -484,10 +484,14 @@ MergeKeyGroups(SymbolsInfo * info,
         if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
             toSize = into->symsMapNumEntries[group][i];
 
-        if ((fromSize != 0 && toSize == 0) || clobber)
+        if (fromSize == 0 || fromSize == toSize || clobber)
+        {
+            fromSize += toSize;
+        }
+        else if (toSize == 0)
+        {
             resultSize += fromSize;
-        else
-            resultSize += toSize;
+        }
     }
 
     if (resultSize == 0)