aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-05-10 23:57:14 +0000
committerKim F. Storm2002-05-10 23:57:14 +0000
commitcd6db61a7a01b56a43cd13c1217239c9738f028d (patch)
treea3adb05ef31a925241ecd21f4539b7c9b11df301
parent6d8c02ae83f2b76051135c4e62a84c33ec967037 (diff)
downloademacs-cd6db61a7a01b56a43cd13c1217239c9738f028d.tar.gz
emacs-cd6db61a7a01b56a43cd13c1217239c9738f028d.zip
(current_minor_maps): Fixed resizing of cmm_maps;
only update cmm_size if realloc actually succeeds. Testing with initial size of 2 elements revealed that using realloc on GNU/Linux would cause a random trap in xmalloc later on, so I rewrote the code to use malloc/bcopy/free instead of realloc.
-rw-r--r--src/keymap.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 60d1b41d2c4..a119a2fa49d 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1248,8 +1248,8 @@ silly_event_symbol_error (c)
1248/* We can't put these variables inside current_minor_maps, since under 1248/* We can't put these variables inside current_minor_maps, since under
1249 some systems, static gets macro-defined to be the empty string. 1249 some systems, static gets macro-defined to be the empty string.
1250 Ickypoo. */ 1250 Ickypoo. */
1251static Lisp_Object *cmm_modes, *cmm_maps; 1251static Lisp_Object *cmm_modes = NULL, *cmm_maps = NULL;
1252static int cmm_size; 1252static int cmm_size = 0;
1253 1253
1254/* Error handler used in current_minor_maps. */ 1254/* Error handler used in current_minor_maps. */
1255static Lisp_Object 1255static Lisp_Object
@@ -1321,40 +1321,41 @@ current_minor_maps (modeptr, mapptr)
1321 1321
1322 if (i >= cmm_size) 1322 if (i >= cmm_size)
1323 { 1323 {
1324 int newsize, allocsize;
1324 Lisp_Object *newmodes, *newmaps; 1325 Lisp_Object *newmodes, *newmaps;
1325 1326
1326 /* Use malloc/realloc here. See the comment above 1327 newsize = cmm_size == 0 ? 30 : cmm_size * 2;
1327 this function. */ 1328 allocsize = newsize * sizeof *newmodes;
1328 if (cmm_maps) 1329
1329 { 1330 /* Use malloc here. See the comment above this function.
1330 BLOCK_INPUT; 1331 Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */
1331 cmm_size *= 2; 1332 BLOCK_INPUT;
1332 newmodes 1333 newmodes = (Lisp_Object *) malloc (allocsize);
1333 = (Lisp_Object *) realloc (cmm_modes, 1334 if (newmodes)
1334 cmm_size * sizeof *newmodes);
1335 newmaps
1336 = (Lisp_Object *) realloc (cmm_maps,
1337 cmm_size * sizeof *newmaps);
1338 UNBLOCK_INPUT;
1339 }
1340 else
1341 { 1335 {
1342 BLOCK_INPUT; 1336 if (cmm_modes)
1343 cmm_size = 30; 1337 {
1344 newmodes 1338 bcopy (cmm_modes, newmodes, cmm_size * sizeof cmm_modes[0]);
1345 = (Lisp_Object *) malloc (cmm_size * sizeof *newmodes); 1339 free (cmm_modes);
1346 newmaps 1340 }
1347 = (Lisp_Object *) malloc (cmm_size * sizeof *newmaps); 1341 cmm_modes = newmodes;
1348 UNBLOCK_INPUT;
1349 } 1342 }
1350 1343
1351 if (newmodes) 1344 newmaps = (Lisp_Object *) malloc (allocsize);
1352 cmm_modes = newmodes;
1353 if (newmaps) 1345 if (newmaps)
1354 cmm_maps = newmaps; 1346 {
1347 if (cmm_maps)
1348 {
1349 bcopy (cmm_maps, newmaps, cmm_size * sizeof cmm_maps[0]);
1350 free (cmm_maps);
1351 }
1352 cmm_maps = newmaps;
1353 }
1354 UNBLOCK_INPUT;
1355 1355
1356 if (newmodes == NULL || newmaps == NULL) 1356 if (newmodes == NULL || newmaps == NULL)
1357 break; 1357 break;
1358 cmm_size = newsize;
1358 } 1359 }
1359 1360
1360 /* Get the keymap definition--or nil if it is not defined. */ 1361 /* Get the keymap definition--or nil if it is not defined. */