Minor string-length refactoring.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 Aug 2013 15:42:08 +0000 (08:42 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 10 Aug 2013 15:42:08 +0000 (08:42 -0700)
* alloc.c (xstrdup): Use memcpy, not strcpy, since the length's known.
* frame.c (make_monitor_attribute_list):
Prefer build_string to strlen + make_string.

src/ChangeLog
src/alloc.c
src/frame.c

index f1293be..976d068 100644 (file)
@@ -1,3 +1,10 @@
+2013-08-10  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Minor string-length refactoring.
+       * alloc.c (xstrdup): Use memcpy, not strcpy, since the length's known.
+       * frame.c (make_monitor_attribute_list):
+       Prefer build_string to strlen + make_string.
+
 2013-08-10  Jan Djärv  <jan.h.d@swipnet.se>
 
        * xterm.c (x_error_handler): Also ignore BadWindow for X_SetInputFocus,
index 19418bd..f9bcaed 100644 (file)
@@ -796,8 +796,10 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
 char *
 xstrdup (const char *s)
 {
+  ptrdiff_t size;
   eassert (s);
-  return strcpy (xmalloc (strlen (s) + 1), s);
+  size = strlen (s) + 1;
+  return memcpy (xmalloc (size), s, size);
 }
 
 /* Like putenv, but (1) use the equivalent of xmalloc and (2) the
index 853ec44..9989ef7 100644 (file)
@@ -725,7 +725,7 @@ affects all frames on the same terminal device.  */)
   XSETFRAME (frame, f);
 
   store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
-  store_in_alist (&parms, Qtty, 
+  store_in_alist (&parms, Qtty,
                  (t->display_info.tty->name
                   ? build_string (t->display_info.tty->name)
                   : Qnil));
@@ -4203,8 +4203,7 @@ make_monitor_attribute_list (struct MonitorInfo *monitors,
                         mi->work.width, mi->work.height);
       geometry = list4i (mi->geom.x, mi->geom.y,
                         mi->geom.width, mi->geom.height);
-      attributes = Fcons (Fcons (Qsource,
-                                 make_string (source, strlen (source))),
+      attributes = Fcons (Fcons (Qsource, build_string (source)),
                           attributes);
       attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
                          attributes);