aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-05 11:35:48 -0700
committerPaul Eggert2012-07-05 11:35:48 -0700
commit38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch)
treea69e1a571495d6ca1c034359d7c995639774ab9b /src/editfns.c
parent6dd5a677dbf794eedaa8325c46d57ac041373361 (diff)
downloademacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz
emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.zip
More xmalloc and related cleanup.
* alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c: * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c: * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c: * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c: * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c: * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c: * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c: * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c: * xterm.c: Omit needless casts involving void * pointers and allocation. Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))", as the former is more robust if P's type is changed. Prefer xzalloc to xmalloc + memset 0. Simplify malloc-or-realloc to realloc. Don't worry about xmalloc returning a null pointer. Prefer xstrdup to xmalloc + strcpy. * editfns.c (Fmessage_box): Grow message_text by at least 80 when growing it. * keyboard.c (apply_modifiers_uncached): Prefer local array to alloca of a constant.
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 5ca68d4f37a..d4146cefb92 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -397,14 +397,14 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
397 397
398 /* First try with room for 40 overlays. */ 398 /* First try with room for 40 overlays. */
399 noverlays = 40; 399 noverlays = 40;
400 overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object)); 400 overlay_vec = alloca (noverlays * sizeof *overlay_vec);
401 noverlays = overlays_around (posn, overlay_vec, noverlays); 401 noverlays = overlays_around (posn, overlay_vec, noverlays);
402 402
403 /* If there are more than 40, 403 /* If there are more than 40,
404 make enough space for all, and try again. */ 404 make enough space for all, and try again. */
405 if (noverlays > 40) 405 if (noverlays > 40)
406 { 406 {
407 overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object)); 407 overlay_vec = alloca (noverlays * sizeof *overlay_vec);
408 noverlays = overlays_around (posn, overlay_vec, noverlays); 408 noverlays = overlays_around (posn, overlay_vec, noverlays);
409 } 409 }
410 noverlays = sort_overlays (overlay_vec, noverlays, NULL); 410 noverlays = sort_overlays (overlay_vec, noverlays, NULL);
@@ -1330,7 +1330,7 @@ name, or nil if there is no such user. */)
1330 Lisp_Object login; 1330 Lisp_Object login;
1331 1331
1332 login = Fuser_login_name (make_number (pw->pw_uid)); 1332 login = Fuser_login_name (make_number (pw->pw_uid));
1333 r = (char *) alloca (strlen (p) + SCHARS (login) + 1); 1333 r = alloca (strlen (p) + SCHARS (login) + 1);
1334 memcpy (r, p, q - p); 1334 memcpy (r, p, q - p);
1335 r[q - p] = 0; 1335 r[q - p] = 0;
1336 strcat (r, SSDATA (login)); 1336 strcat (r, SSDATA (login));
@@ -2154,7 +2154,7 @@ set_time_zone_rule (const char *tzstring)
2154 for (from = environ; *from; from++) 2154 for (from = environ; *from; from++)
2155 continue; 2155 continue;
2156 envptrs = from - environ + 2; 2156 envptrs = from - environ + 2;
2157 newenv = to = xmalloc (envptrs * sizeof (char *) 2157 newenv = to = xmalloc (envptrs * sizeof *newenv
2158 + (tzstring ? strlen (tzstring) + 4 : 0)); 2158 + (tzstring ? strlen (tzstring) + 4 : 0));
2159 2159
2160 /* Add TZSTRING to the end of environ, as a value for TZ. */ 2160 /* Add TZSTRING to the end of environ, as a value for TZ. */
@@ -3472,15 +3472,11 @@ usage: (message-box FORMAT-STRING &rest ARGS) */)
3472 } 3472 }
3473#endif /* HAVE_MENUS */ 3473#endif /* HAVE_MENUS */
3474 /* Copy the data so that it won't move when we GC. */ 3474 /* Copy the data so that it won't move when we GC. */
3475 if (! message_text)
3476 {
3477 message_text = xmalloc (80);
3478 message_length = 80;
3479 }
3480 if (SBYTES (val) > message_length) 3475 if (SBYTES (val) > message_length)
3481 { 3476 {
3482 message_text = (char *) xrealloc (message_text, SBYTES (val)); 3477 ptrdiff_t new_length = SBYTES (val) + 80;
3483 message_length = SBYTES (val); 3478 message_text = xrealloc (message_text, new_length);
3479 message_length = new_length;
3484 } 3480 }
3485 memcpy (message_text, SDATA (val), SBYTES (val)); 3481 memcpy (message_text, SDATA (val), SBYTES (val));
3486 message2 (message_text, SBYTES (val), 3482 message2 (message_text, SBYTES (val),