Use xstrdup and build_unibyte_string where applicable.
authorDmitry Antipov <dmantipov@yandex.ru>
Fri, 9 Aug 2013 12:25:34 +0000 (16:25 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Fri, 9 Aug 2013 12:25:34 +0000 (16:25 +0400)
* alloc.c (xstrdup): Tiny cleanup.  Add eassert.
* xfns.c (x_window):
* xrdb.c (x_get_customization_string):
* xterm.c (xim_initialize):
* w32fns.c (w32_window): Use xstrdup.
(w32_display_monitor_attributes_list):
* emacs.c (init_cmdargs):
* keyboard.c (PUSH_C_STR):
* nsfont.m (nsfont_open):
* sysdep.c (system_process_attributes):
* w32.c (system_process_attributes):
* xdisp.c (message1, message1_nolog): Use build_unibyte_string.

12 files changed:
src/ChangeLog
src/alloc.c
src/emacs.c
src/keyboard.c
src/nsfont.m
src/sysdep.c
src/w32.c
src/w32fns.c
src/xdisp.c
src/xfns.c
src/xrdb.c
src/xterm.c

index aa424d2..bd8aae8 100644 (file)
@@ -1,3 +1,19 @@
+2013-08-09  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Use xstrdup and build_unibyte_string where applicable.
+       * alloc.c (xstrdup): Tiny cleanup.  Add eassert.
+       * xfns.c (x_window):
+       * xrdb.c (x_get_customization_string):
+       * xterm.c (xim_initialize):
+       * w32fns.c (w32_window): Use xstrdup.
+       (w32_display_monitor_attributes_list):
+       * emacs.c (init_cmdargs):
+       * keyboard.c (PUSH_C_STR):
+       * nsfont.m (nsfont_open):
+       * sysdep.c (system_process_attributes):
+       * w32.c (system_process_attributes):
+       * xdisp.c (message1, message1_nolog): Use build_unibyte_string.
+
 2013-08-09  Eli Zaretskii  <eliz@gnu.org>
 
        * w32.c (PEXCEPTION_POINTERS, PEXCEPTION_RECORD, PCONTEXT): Define
index c8141d2..19418bd 100644 (file)
@@ -796,10 +796,8 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
 char *
 xstrdup (const char *s)
 {
-  size_t len = strlen (s) + 1;
-  char *p = xmalloc (len);
-  memcpy (p, s, len);
-  return p;
+  eassert (s);
+  return strcpy (xmalloc (strlen (s) + 1), s);
 }
 
 /* Like putenv, but (1) use the equivalent of xmalloc and (2) the
index cf3a3c6..23aef6a 100644 (file)
@@ -517,8 +517,7 @@ init_cmdargs (int argc, char **argv, int skip_args)
           They are decoded in the function command-line after we know
           locale-coding-system.  */
        Vcommand_line_args
-         = Fcons (make_unibyte_string (argv[i], strlen (argv[i])),
-                  Vcommand_line_args);
+         = Fcons (build_unibyte_string (argv[i]), Vcommand_line_args);
     }
 
   unbind_to (count, Qnil);
index c026b16..3afdce4 100644 (file)
@@ -8431,7 +8431,7 @@ read_char_minibuf_menu_prompt (int commandflag,
     return Qnil;
 
 #define PUSH_C_STR(str, listvar) \
-  listvar = Fcons (make_unibyte_string (str, strlen (str)), listvar)
+  listvar = Fcons (build_unibyte_string (str), listvar)
 
   /* Prompt string always starts with map's prompt, and a space.  */
   prompt_strings = Fcons (name, prompt_strings);
index ad169d7..235150e 100644 (file)
@@ -920,8 +920,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
     font->underline_thickness = lrint (font_info->underwidth);
 
     font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil);
-    font->props[FONT_FULLNAME_INDEX] =
-      make_unibyte_string (font_info->name, strlen (font_info->name));
+    font->props[FONT_FULLNAME_INDEX] = build_unibyte_string (font_info->name);
   }
   unblock_input ();
 
index 11a6f4a..201ba9d 100644 (file)
@@ -3243,13 +3243,11 @@ system_process_attributes (Lisp_Object pid)
                     attrs);
 
       decoded_cmd = (code_convert_string_norecord
-                    (make_unibyte_string (pinfo.pr_fname,
-                                          strlen (pinfo.pr_fname)),
+                    (build_unibyte_string (pinfo.pr_fname),
                      Vlocale_coding_system, 0));
       attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
       decoded_cmd = (code_convert_string_norecord
-                    (make_unibyte_string (pinfo.pr_psargs,
-                                          strlen (pinfo.pr_psargs)),
+                    (build_unibyte_string (pinfo.pr_psargs),
                      Vlocale_coding_system, 0));
       attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
     }
@@ -3319,9 +3317,9 @@ system_process_attributes (Lisp_Object pid)
   if (gr)
     attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
 
-  decoded_comm = code_convert_string_norecord
-    (make_unibyte_string (proc.ki_comm, strlen (proc.ki_comm)),
-     Vlocale_coding_system, 0);
+  decoded_comm = (code_convert_string_norecord
+                 (build_unibyte_string (proc.ki_comm),
+                  Vlocale_coding_system, 0));
 
   attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
   {
index 9b87cfc..21dbf49 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -5769,8 +5769,8 @@ system_process_attributes (Lisp_Object pid)
                {
                  /* Decode the command name from locale-specific
                     encoding.  */
-                 cmd_str = make_unibyte_string (pe.szExeFile,
-                                                strlen (pe.szExeFile));
+                 cmd_str = build_unibyte_string (pe.szExeFile);
+
                  decoded_cmd =
                    code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
index dff35de..c43b7d4 100644 (file)
@@ -4124,12 +4124,7 @@ w32_window (struct frame *f, long window_prompting, int minibuffer_only)
      for the window manager, so GC relocation won't bother it.
 
      Elsewhere we specify the window name for the window manager.  */
-
-  {
-    char *str = SSDATA (Vx_resource_name);
-    f->namebuf = xmalloc (strlen (str) + 1);
-    strcpy (f->namebuf, str);
-  }
+  f->namebuf = xstrdup (SSDATA (Vx_resource_name));
 
   my_create_window (f);
 
@@ -4992,8 +4987,8 @@ w32_display_monitor_attributes_list (void)
       attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
                          attributes);
 
-      name = DECODE_SYSTEM (make_unibyte_string (mi.szDevice,
-                                                strlen (mi.szDevice)));
+      name = DECODE_SYSTEM (build_unibyte_string (mi.szDevice));
+
       attributes = Fcons (Fcons (Qname, name), attributes);
 
       attributes = Fcons (Fcons (Qmm_size, list2i (width_mm, height_mm)),
index ab625b9..aee24e2 100644 (file)
@@ -9789,7 +9789,7 @@ message3_nolog (Lisp_Object m)
 void
 message1 (const char *m)
 {
-  message3 (m ? make_unibyte_string (m, strlen (m)) : Qnil);
+  message3 (m ? build_unibyte_string (m) : Qnil);
 }
 
 
@@ -9798,7 +9798,7 @@ message1 (const char *m)
 void
 message1_nolog (const char *m)
 {
-  message3_nolog (m ? make_unibyte_string (m, strlen (m)) : Qnil);
+  message3_nolog (m ? build_unibyte_string (m) : Qnil);
 }
 
 /* Display a message M which contains a single %s
index a1e9e91..92a7964 100644 (file)
@@ -2313,12 +2313,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
      for the window manager, so GC relocation won't bother it.
 
      Elsewhere we specify the window name for the window manager.  */
-
-  {
-    char *str = SSDATA (Vx_resource_name);
-    f->namebuf = xmalloc (strlen (str) + 1);
-    strcpy (f->namebuf, str);
-  }
+  f->namebuf = xstrdup (SSDATA (Vx_resource_name));
 
   ac = 0;
   XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
index 7c9cd53..6ef5c3b 100644 (file)
@@ -75,18 +75,9 @@ x_get_customization_string (XrmDatabase db, const char *name,
   sprintf (full_class, "%s.%s", class, "Customization");
 
   result = x_get_string_resource (db, full_name, full_class);
-
-  if (result)
-    {
-      char *copy = xmalloc (strlen (result) + 1);
-      strcpy (copy, result);
-      return copy;
-    }
-  else
-    return 0;
+  return result ? xstrdup (result) : NULL;
 }
 
-
 /* Expand all the Xt-style %-escapes in STRING, whose length is given
    by STRING_LEN.  Here are the escapes we're supposed to recognize:
 
index 6391154..db5ca1a 100644 (file)
@@ -8081,13 +8081,10 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
     {
 #ifdef HAVE_X11R6_XIM
       struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst);
-      ptrdiff_t len;
 
       dpyinfo->xim_callback_data = xim_inst;
       xim_inst->dpyinfo = dpyinfo;
-      len = strlen (resource_name);
-      xim_inst->resource_name = xmalloc (len + 1);
-      memcpy (xim_inst->resource_name, resource_name, len + 1);
+      xim_inst->resource_name = xstrdup (resource_name);
       XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
                                      resource_name, emacs_class,
                                      xim_instantiate_callback,