aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.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/sysdep.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/sysdep.c')
-rw-r--r--src/sysdep.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index afab85439f3..7a4fa9aa5f7 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -143,7 +143,7 @@ get_current_dir_name (void)
143#endif 143#endif
144 ) 144 )
145 { 145 {
146 buf = (char *) malloc (strlen (pwd) + 1); 146 buf = malloc (strlen (pwd) + 1);
147 if (!buf) 147 if (!buf)
148 return NULL; 148 return NULL;
149 strcpy (buf, pwd); 149 strcpy (buf, pwd);
@@ -152,7 +152,7 @@ get_current_dir_name (void)
152 else 152 else
153 { 153 {
154 size_t buf_size = 1024; 154 size_t buf_size = 1024;
155 buf = (char *) malloc (buf_size); 155 buf = malloc (buf_size);
156 if (!buf) 156 if (!buf)
157 return NULL; 157 return NULL;
158 for (;;) 158 for (;;)
@@ -167,7 +167,7 @@ get_current_dir_name (void)
167 return NULL; 167 return NULL;
168 } 168 }
169 buf_size *= 2; 169 buf_size *= 2;
170 buf = (char *) realloc (buf, buf_size); 170 buf = realloc (buf, buf_size);
171 if (!buf) 171 if (!buf)
172 return NULL; 172 return NULL;
173 } 173 }
@@ -176,7 +176,7 @@ get_current_dir_name (void)
176 else 176 else
177 { 177 {
178 /* We need MAXPATHLEN here. */ 178 /* We need MAXPATHLEN here. */
179 buf = (char *) malloc (MAXPATHLEN + 1); 179 buf = malloc (MAXPATHLEN + 1);
180 if (!buf) 180 if (!buf)
181 return NULL; 181 return NULL;
182 if (getwd (buf) == NULL) 182 if (getwd (buf) == NULL)
@@ -516,7 +516,7 @@ sys_subshell (void)
516 goto xyzzy; 516 goto xyzzy;
517 517
518 dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil); 518 dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
519 str_volatile = str = (unsigned char *) alloca (SCHARS (dir) + 2); 519 str_volatile = str = alloca (SCHARS (dir) + 2);
520 len = SCHARS (dir); 520 len = SCHARS (dir);
521 memcpy (str, SDATA (dir), len); 521 memcpy (str, SDATA (dir), len);
522 if (str[len - 1] != '/') str[len++] = '/'; 522 if (str[len - 1] != '/') str[len++] = '/';
@@ -851,7 +851,7 @@ init_sys_modes (struct tty_display_info *tty_out)
851 return; /* The tty is suspended. */ 851 return; /* The tty is suspended. */
852 852
853 if (! tty_out->old_tty) 853 if (! tty_out->old_tty)
854 tty_out->old_tty = xmalloc (sizeof (struct emacs_tty)); 854 tty_out->old_tty = xmalloc (sizeof *tty_out->old_tty);
855 855
856 emacs_get_tty (fileno (tty_out->input), tty_out->old_tty); 856 emacs_get_tty (fileno (tty_out->input), tty_out->old_tty);
857 857
@@ -1345,7 +1345,7 @@ init_system_name (void)
1345 Vsystem_name = build_string (uts.nodename); 1345 Vsystem_name = build_string (uts.nodename);
1346#else /* HAVE_GETHOSTNAME */ 1346#else /* HAVE_GETHOSTNAME */
1347 unsigned int hostname_size = 256; 1347 unsigned int hostname_size = 256;
1348 char *hostname = (char *) alloca (hostname_size); 1348 char *hostname = alloca (hostname_size);
1349 1349
1350 /* Try to get the host name; if the buffer is too short, try 1350 /* Try to get the host name; if the buffer is too short, try
1351 again. Apparently, the only indication gethostname gives of 1351 again. Apparently, the only indication gethostname gives of
@@ -1361,7 +1361,7 @@ init_system_name (void)
1361 break; 1361 break;
1362 1362
1363 hostname_size <<= 1; 1363 hostname_size <<= 1;
1364 hostname = (char *) alloca (hostname_size); 1364 hostname = alloca (hostname_size);
1365 } 1365 }
1366#ifdef HAVE_SOCKETS 1366#ifdef HAVE_SOCKETS
1367 /* Turn the hostname into the official, fully-qualified hostname. 1367 /* Turn the hostname into the official, fully-qualified hostname.