]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix some slow uses and misuses of strcat.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Sep 2014 04:12:37 +0000 (21:12 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Sep 2014 04:12:37 +0000 (21:12 -0700)
* doc.c (get_doc_string):
* gtkutil.c (get_utf8_string):
* xsmfns.c (x_session_initialize):
Avoid recomputation of string length.
* ftfont.c (ftfont_spec_pattern):
* xfns.c (xic_create_fontsetname):
Don't assume output buffer is initially zero.

src/ChangeLog
src/doc.c
src/ftfont.c
src/gtkutil.c
src/xfns.c
src/xsmfns.c

index 7f05f6fe21f4f82d5f07001b6e168b3af7fb763c..0fc4c2b1599660293ecb48fb3d3825591cf75298 100644 (file)
@@ -1,3 +1,14 @@
+2014-09-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix some slow uses and misuses of strcat.
+       * doc.c (get_doc_string):
+       * gtkutil.c (get_utf8_string):
+       * xsmfns.c (x_session_initialize):
+       Avoid recomputation of string length.
+       * ftfont.c (ftfont_spec_pattern):
+       * xfns.c (xic_create_fontsetname):
+       Don't assume output buffer is initially zero.
+
 2014-09-23  Paul Eggert  <eggert@cs.ucla.edu>
 
        * lisp.h (lispstpcpy): Rename from lispstrcpy, and act like stpcpy.
index fdd7be6def92fc4f1b27495373316631d2392a57..bbb42c2aa3fdaab376cc5168cdd985611bd5b081 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -121,8 +121,8 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
       if (minsize < 8)
        minsize = 8;
       name = SAFE_ALLOCA (minsize + SCHARS (file) + 8);
-      lispstpcpy (name, docdir);
-      strcat (name, SSDATA (file));
+      char *z = lispstpcpy (name, docdir);
+      strcpy (z, SSDATA (file));
     }
   else
     {
index 0ab3119365e175e120526214e8f07113c6d577e9..4c12ef5d3afe0e467e39e552e33b7df269737cc2 100644 (file)
@@ -804,7 +804,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots
              *otspec = ftfont_get_open_type_spec (val);
              if (! *otspec)
                return NULL;
-             strcat (otlayout, "otlayout:");
+             strcpy (otlayout, "otlayout:");
              OTF_TAG_STR ((*otspec)->script_tag, otlayout + 9);
              script = (*otspec)->script;
            }
index 62f2c1b0682d147be140f050f9c0094ec0436535..1f3e1958ede810aaf1898695e8939afcde2db875 100644 (file)
@@ -508,16 +508,16 @@ get_utf8_string (const char *str)
              && err->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE)
         {
           memcpy (up, p, bytes_written);
-          sprintf (up + bytes_written, "\\%03o", p[bytes_written]);
-          up += bytes_written+4;
-          p += bytes_written+1;
+          up += bytes_written;
+          up += sprintf (up, "\\%03o", p[bytes_written]);
+          p += bytes_written + 1;
           g_error_free (err);
           err = NULL;
         }
 
       if (cp)
         {
-          strcat (utf8_str, cp);
+          strcpy (up, cp);
           g_free (cp);
         }
       if (err)
index c2e39b5c0a678a020a6014dc6e1220ff0a5a2a81..63978c27f463d64e13456c8db8231f56cd551e8b 100644 (file)
@@ -1786,7 +1786,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
          len = p - base_fontname + strlen (allcs) + 1;
          font_allcs = alloca (len);
          memcpy (font_allcs, base_fontname, p - base_fontname);
-         strcat (font_allcs, allcs);
+         strcpy (font_allcs + (p - base_fontname), allcs);
 
          /* Build the font spec that matches all families and
             add-styles.  */
@@ -1794,7 +1794,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
          font_allfamilies = alloca (len);
          strcpy (font_allfamilies, allfamilies);
          memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1);
-         strcat (font_allfamilies, allcs);
+         strcpy (font_allfamilies + strlen (allfamilies) + (p - p1), allcs);
 
          /* Build the font spec that matches all.  */
          len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
@@ -1802,7 +1802,8 @@ xic_create_fontsetname (const char *base_fontname, int motif)
          strcpy (font_all, allfamilies);
          strcat (font_all, all);
          memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2);
-         strcat (font_all, allcs);
+         strcpy (font_all + strlen (all) + strlen (allfamilies) + (p - p2),
+                 allcs);
 
          /* Build the actual font set name.  */
          len = strlen (base_fontname) + strlen (font_allcs)
index ed67a7d8e1fe8b097e5b5e5e0261754edb93d6ad..cd4f9ce57fa9d5aa008cf492399b73b3d10ac5bc 100644 (file)
@@ -415,11 +415,11 @@ x_session_initialize (struct x_display_info *dpyinfo)
   /* This malloc will not be freed, but it is only done once, and hopefully
      not very large   */
   emacs_program = xmalloc (name_len + 1);
-  emacs_program[0] = '\0';
+  char *z = emacs_program;
 
   if (! EQ (Vinvocation_directory, Qnil))
-    lispstpcpy (emacs_program, Vinvocation_directory);
-  strcat (emacs_program, SSDATA (Vinvocation_name));
+    z = lispstpcpy (z, Vinvocation_directory);
+  lispstpcpy (z, Vinvocation_name);
 
   /* The SM protocol says all callbacks are mandatory, so set up all
      here and in the mask passed to SmcOpenConnection.  */