From 9acc107445a159001e56bae04ef2dc2792aa16d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Aug 2013 08:42:08 -0700 Subject: [PATCH] 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. --- src/ChangeLog | 7 +++++++ src/alloc.c | 4 +++- src/frame.c | 5 ++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f1293be9855..976d068dadc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2013-08-10 Paul Eggert + + 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 * xterm.c (x_error_handler): Also ignore BadWindow for X_SetInputFocus, diff --git a/src/alloc.c b/src/alloc.c index 19418bd6686..f9bcaed0117 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -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 diff --git a/src/frame.c b/src/frame.c index 853ec441343..9989ef7af13 100644 --- a/src/frame.c +++ b/src/frame.c @@ -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); -- 2.39.2