aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2014-12-25 04:19:17 -0800
committerPaul Eggert2014-12-25 15:44:23 -0800
commit1e6879dbdb0832427f5c588c89a53a8a80768a00 (patch)
tree155493c6e140264c05356c667a1c9547a45e336f /src
parent8dba53d239f5ac00e930f13b73f59cb5b53ffbd1 (diff)
downloademacs-1e6879dbdb0832427f5c588c89a53a8a80768a00.tar.gz
emacs-1e6879dbdb0832427f5c588c89a53a8a80768a00.zip
Prefer stpcpy to strcat
* admin/merge-gnulib (GNULIB_MODULES): Add stpcpy. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * lib/stpcpy.c, m4/stpcpy.m4: New files, from gnulib. * lib-src/ebrowse.c (sym_scope_1, operator_name, open_file): * lib-src/emacsclient.c (get_server_config, set_local_socket) (start_daemon_and_retry_set_socket): * lib-src/etags.c (main, C_entries, relative_filename): * lib-src/pop.c (sendline): * lib-src/update-game-score.c (main): * lwlib/xlwmenu.c (resource_widget_value): * src/callproc.c (child_setup): * src/dbusbind.c (xd_signature_cat): * src/doc.c (get_doc_string, Fsnarf_documentation): * src/editfns.c (Fuser_full_name): * src/frame.c (xrdb_get_resource): * src/gtkutil.c (xg_get_file_with_chooser): * src/tparam.c (tparam1): * src/xfns.c (xic_create_fontsetname): * src/xrdb.c (gethomedir, get_user_db, get_environ_db): * src/xsmfns.c (smc_save_yourself_CB): Rewrite to avoid the need for strcat, typically by using stpcpy and/or lispstpcpy. strcat tends to be part of O(N**2) algorithms. * src/doc.c (sibling_etc): * src/xrdb.c (xdefaults): Now a top-level static constant.
Diffstat (limited to 'src')
-rw-r--r--src/callproc.c7
-rw-r--r--src/dbusbind.c2
-rw-r--r--src/doc.c33
-rw-r--r--src/editfns.c5
-rw-r--r--src/frame.c20
-rw-r--r--src/gtkutil.c6
-rw-r--r--src/tparam.c4
-rw-r--r--src/xfns.c34
-rw-r--r--src/xrdb.c44
-rw-r--r--src/xsmfns.c6
10 files changed, 71 insertions, 90 deletions
diff --git a/src/callproc.c b/src/callproc.c
index a677334b3b7..f40ed3244a5 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1315,13 +1315,10 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1315 1315
1316 if (STRINGP (display)) 1316 if (STRINGP (display))
1317 { 1317 {
1318 char *vdata;
1319
1320 if (MAX_ALLOCA - sizeof "DISPLAY=" < SBYTES (display)) 1318 if (MAX_ALLOCA - sizeof "DISPLAY=" < SBYTES (display))
1321 exec_failed (new_argv[0], ENOMEM); 1319 exec_failed (new_argv[0], ENOMEM);
1322 vdata = alloca (sizeof "DISPLAY=" + SBYTES (display)); 1320 char *vdata = alloca (sizeof "DISPLAY=" + SBYTES (display));
1323 strcpy (vdata, "DISPLAY="); 1321 lispstpcpy (stpcpy (vdata, "DISPLAY="), display);
1324 strcat (vdata, SSDATA (display));
1325 new_env = add_env (env, new_env, vdata); 1322 new_env = add_env (env, new_env, vdata);
1326 } 1323 }
1327 1324
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4852739d8e4..983b05c4206 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -357,7 +357,7 @@ xd_signature_cat (char *signature, char const *x)
357 ptrdiff_t xlen = strlen (x); 357 ptrdiff_t xlen = strlen (x);
358 if (DBUS_MAXIMUM_SIGNATURE_LENGTH - xlen <= siglen) 358 if (DBUS_MAXIMUM_SIGNATURE_LENGTH - xlen <= siglen)
359 string_overflow (); 359 string_overflow ();
360 strcat (signature, x); 360 strcpy (signature + siglen, x);
361} 361}
362 362
363/* Compute SIGNATURE of OBJECT. It must have a form that it can be 363/* Compute SIGNATURE of OBJECT. It must have a form that it can be
diff --git a/src/doc.c b/src/doc.c
index 1b87c23e949..1d9c330d12c 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -42,6 +42,8 @@ static ptrdiff_t get_doc_string_buffer_size;
42 42
43static unsigned char *read_bytecode_pointer; 43static unsigned char *read_bytecode_pointer;
44 44
45static char const sibling_etc[] = "../etc/";
46
45/* `readchar' in lread.c calls back here to fetch the next byte. 47/* `readchar' in lread.c calls back here to fetch the next byte.
46 If UNREADFLAG is 1, we unread a byte. */ 48 If UNREADFLAG is 1, we unread a byte. */
47 49
@@ -80,7 +82,6 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
80{ 82{
81 char *from, *to, *name, *p, *p1; 83 char *from, *to, *name, *p, *p1;
82 int fd; 84 int fd;
83 ptrdiff_t minsize;
84 int offset; 85 int offset;
85 EMACS_INT position; 86 EMACS_INT position;
86 Lisp_Object file, tem, pos; 87 Lisp_Object file, tem, pos;
@@ -113,21 +114,14 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
113 114
114 tem = Ffile_name_absolute_p (file); 115 tem = Ffile_name_absolute_p (file);
115 file = ENCODE_FILE (file); 116 file = ENCODE_FILE (file);
116 if (NILP (tem)) 117 Lisp_Object docdir
117 { 118 = NILP (tem) ? ENCODE_FILE (Vdoc_directory) : empty_unibyte_string;
118 Lisp_Object docdir = ENCODE_FILE (Vdoc_directory); 119 ptrdiff_t docdir_sizemax = SBYTES (docdir) + 1;
119 minsize = SCHARS (docdir); 120#ifndef CANNOT_DUMP
120 /* sizeof ("../etc/") == 8 */ 121 docdir_sizemax = max (docdir_sizemax, sizeof sibling_etc);
121 if (minsize < 8) 122#endif
122 minsize = 8; 123 name = SAFE_ALLOCA (docdir_sizemax + SBYTES (file));
123 name = SAFE_ALLOCA (minsize + SCHARS (file) + 8); 124 lispstpcpy (lispstpcpy (name, docdir), file);
124 char *z = lispstpcpy (name, docdir);
125 strcpy (z, SSDATA (file));
126 }
127 else
128 {
129 name = SSDATA (file);
130 }
131 125
132 fd = emacs_open (name, O_RDONLY, 0); 126 fd = emacs_open (name, O_RDONLY, 0);
133 if (fd < 0) 127 if (fd < 0)
@@ -137,8 +131,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
137 { 131 {
138 /* Preparing to dump; DOC file is probably not installed. 132 /* Preparing to dump; DOC file is probably not installed.
139 So check in ../etc. */ 133 So check in ../etc. */
140 strcpy (name, "../etc/"); 134 lispstpcpy (stpcpy (name, sibling_etc), file);
141 strcat (name, SSDATA (file));
142 135
143 fd = emacs_open (name, O_RDONLY, 0); 136 fd = emacs_open (name, O_RDONLY, 0);
144 } 137 }
@@ -580,7 +573,6 @@ the same file name is found in the `doc-directory'. */)
580 (0) 573 (0)
581#endif /* CANNOT_DUMP */ 574#endif /* CANNOT_DUMP */
582 { 575 {
583 static char const sibling_etc[] = "../etc/";
584 dirname = sibling_etc; 576 dirname = sibling_etc;
585 dirlen = sizeof sibling_etc - 1; 577 dirlen = sizeof sibling_etc - 1;
586 } 578 }
@@ -594,8 +586,7 @@ the same file name is found in the `doc-directory'. */)
594 count = SPECPDL_INDEX (); 586 count = SPECPDL_INDEX ();
595 USE_SAFE_ALLOCA; 587 USE_SAFE_ALLOCA;
596 name = SAFE_ALLOCA (dirlen + SBYTES (filename) + 1); 588 name = SAFE_ALLOCA (dirlen + SBYTES (filename) + 1);
597 strcpy (name, dirname); 589 lispstpcpy (stpcpy (name, dirname), filename); /*** Add this line ***/
598 strcat (name, SSDATA (filename)); /*** Add this line ***/
599 590
600 /* Vbuild_files is nil when temacs is run, and non-nil after that. */ 591 /* Vbuild_files is nil when temacs is run, and non-nil after that. */
601 if (NILP (Vbuild_files)) 592 if (NILP (Vbuild_files))
diff --git a/src/editfns.c b/src/editfns.c
index 0a07886934c..430c4c91fb3 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1350,10 +1350,9 @@ name, or nil if there is no such user. */)
1350 USE_SAFE_ALLOCA; 1350 USE_SAFE_ALLOCA;
1351 char *r = SAFE_ALLOCA (strlen (p) + SBYTES (login) + 1); 1351 char *r = SAFE_ALLOCA (strlen (p) + SBYTES (login) + 1);
1352 memcpy (r, p, q - p); 1352 memcpy (r, p, q - p);
1353 r[q - p] = 0; 1353 char *s = lispstpcpy (&r[q - p], login);
1354 strcat (r, SSDATA (login));
1355 r[q - p] = upcase ((unsigned char) r[q - p]); 1354 r[q - p] = upcase ((unsigned char) r[q - p]);
1356 strcat (r, q + 1); 1355 strcpy (s, q + 1);
1357 full = build_string (r); 1356 full = build_string (r);
1358 SAFE_FREE (); 1357 SAFE_FREE ();
1359 } 1358 }
diff --git a/src/frame.c b/src/frame.c
index 31273665e88..2ad1c1b52b7 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -4076,23 +4076,23 @@ xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Li
4076 4076
4077 /* Start with emacs.FRAMENAME for the name (the specific one) 4077 /* Start with emacs.FRAMENAME for the name (the specific one)
4078 and with `Emacs' for the class key (the general one). */ 4078 and with `Emacs' for the class key (the general one). */
4079 lispstpcpy (name_key, Vx_resource_name); 4079 char *nz = lispstpcpy (name_key, Vx_resource_name);
4080 lispstpcpy (class_key, Vx_resource_class); 4080 char *cz = lispstpcpy (class_key, Vx_resource_class);
4081 4081
4082 strcat (class_key, "."); 4082 *cz++ = '.';
4083 strcat (class_key, SSDATA (class)); 4083 cz = lispstpcpy (cz, class);
4084 4084
4085 if (!NILP (component)) 4085 if (!NILP (component))
4086 { 4086 {
4087 strcat (class_key, "."); 4087 *cz++ = '.';
4088 strcat (class_key, SSDATA (subclass)); 4088 lispstpcpy (cz, subclass);
4089 4089
4090 strcat (name_key, "."); 4090 *nz++ = '.';
4091 strcat (name_key, SSDATA (component)); 4091 nz = lispstpcpy (nz, component);
4092 } 4092 }
4093 4093
4094 strcat (name_key, "."); 4094 *nz++ = '.';
4095 strcat (name_key, SSDATA (attribute)); 4095 lispstpcpy (nz, attribute);
4096 4096
4097 char *value = x_get_string_resource (rdb, name_key, class_key); 4097 char *value = x_get_string_resource (rdb, name_key, class_key);
4098 SAFE_FREE(); 4098 SAFE_FREE();
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 9465d5479df..f61cbc2c85c 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1839,12 +1839,12 @@ xg_get_file_with_chooser (struct frame *f,
1839 1839
1840 if (x_gtk_file_dialog_help_text) 1840 if (x_gtk_file_dialog_help_text)
1841 { 1841 {
1842 msgbuf[0] = '\0'; 1842 char *z = msgbuf;
1843 /* Gtk+ 2.10 has the file name text entry box integrated in the dialog. 1843 /* Gtk+ 2.10 has the file name text entry box integrated in the dialog.
1844 Show the C-l help text only for versions < 2.10. */ 1844 Show the C-l help text only for versions < 2.10. */
1845 if (gtk_check_version (2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE) 1845 if (gtk_check_version (2, 10, 0) && action != GTK_FILE_CHOOSER_ACTION_SAVE)
1846 strcat (msgbuf, "\nType C-l to display a file name text entry box.\n"); 1846 z = stpcpy (z, "\nType C-l to display a file name text entry box.\n");
1847 strcat (msgbuf, "\nIf you don't like this file selector, use the " 1847 strcpy (z, "\nIf you don't like this file selector, use the "
1848 "corresponding\nkey binding or customize " 1848 "corresponding\nkey binding or customize "
1849 "use-file-dialog to turn it off."); 1849 "use-file-dialog to turn it off.");
1850 1850
diff --git a/src/tparam.c b/src/tparam.c
index e02cea3689e..b0cd0047ba2 100644
--- a/src/tparam.c
+++ b/src/tparam.c
@@ -255,9 +255,9 @@ tparam1 (const char *string, char *outstring, int len,
255 } 255 }
256 *op = 0; 256 *op = 0;
257 while (doup-- > 0) 257 while (doup-- > 0)
258 strcat (op, up); 258 op = stpcpy (op, up);
259 while (doleft-- > 0) 259 while (doleft-- > 0)
260 strcat (op, left); 260 op = stpcpy (op, left);
261 return outstring; 261 return outstring;
262} 262}
263 263
diff --git a/src/xfns.c b/src/xfns.c
index 1b17311f99c..ba2601daca4 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1710,13 +1710,14 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1710{ 1710{
1711 const char *sep = motif ? ";" : ","; 1711 const char *sep = motif ? ";" : ",";
1712 char *fontsetname; 1712 char *fontsetname;
1713 char *z;
1713 1714
1714 /* Make a fontset name from the base font name. */ 1715 /* Make a fontset name from the base font name. */
1715 if (xic_default_fontset == base_fontname) 1716 if (xic_default_fontset == base_fontname)
1716 { 1717 {
1717 /* There is no base font name, use the default. */ 1718 /* There is no base font name, use the default. */
1718 fontsetname = xmalloc (strlen (base_fontname) + 2); 1719 fontsetname = xmalloc (strlen (base_fontname) + 2);
1719 strcpy (fontsetname, base_fontname); 1720 z = stpcpy (fontsetname, base_fontname);
1720 } 1721 }
1721 else 1722 else
1722 { 1723 {
@@ -1737,9 +1738,9 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1737 Use the specified font plus the default. */ 1738 Use the specified font plus the default. */
1738 fontsetname = xmalloc (strlen (base_fontname) 1739 fontsetname = xmalloc (strlen (base_fontname)
1739 + strlen (xic_default_fontset) + 3); 1740 + strlen (xic_default_fontset) + 3);
1740 strcpy (fontsetname, base_fontname); 1741 z = stpcpy (fontsetname, base_fontname);
1741 strcat (fontsetname, sep); 1742 z = stpcpy (z, sep);
1742 strcat (fontsetname, xic_default_fontset); 1743 z = stpcpy (z, xic_default_fontset);
1743 } 1744 }
1744 else 1745 else
1745 { 1746 {
@@ -1800,27 +1801,26 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1800 /* Build the font spec that matches all. */ 1801 /* Build the font spec that matches all. */
1801 len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1; 1802 len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
1802 font_all = alloca (len); 1803 font_all = alloca (len);
1803 strcpy (font_all, allfamilies); 1804 z = stpcpy (font_all, allfamilies);
1804 strcat (font_all, all); 1805 z = stpcpy (z, all);
1805 memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2); 1806 memcpy (z, p2, p - p2);
1806 strcpy (font_all + strlen (all) + strlen (allfamilies) + (p - p2), 1807 strcpy (z + (p - p2), allcs);
1807 allcs);
1808 1808
1809 /* Build the actual font set name. */ 1809 /* Build the actual font set name. */
1810 len = strlen (base_fontname) + strlen (font_allcs) 1810 len = strlen (base_fontname) + strlen (font_allcs)
1811 + strlen (font_allfamilies) + strlen (font_all) + 5; 1811 + strlen (font_allfamilies) + strlen (font_all) + 5;
1812 fontsetname = xmalloc (len); 1812 fontsetname = xmalloc (len);
1813 strcpy (fontsetname, base_fontname); 1813 z = stpcpy (fontsetname, base_fontname);
1814 strcat (fontsetname, sep); 1814 z = stpcpy (z, sep);
1815 strcat (fontsetname, font_allcs); 1815 z = stpcpy (z, font_allcs);
1816 strcat (fontsetname, sep); 1816 z = stpcpy (z, sep);
1817 strcat (fontsetname, font_allfamilies); 1817 z = stpcpy (z, font_allfamilies);
1818 strcat (fontsetname, sep); 1818 z = stpcpy (z, sep);
1819 strcat (fontsetname, font_all); 1819 z = stpcpy (z, font_all);
1820 } 1820 }
1821 } 1821 }
1822 if (motif) 1822 if (motif)
1823 return strcat (fontsetname, ":"); 1823 strcpy (z, ":");
1824 return fontsetname; 1824 return fontsetname;
1825} 1825}
1826#endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ 1826#endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
diff --git a/src/xrdb.c b/src/xrdb.c
index 32ad3c7f01e..e21206d0800 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -232,9 +232,10 @@ gethomedir (void)
232 if (ptr == NULL) 232 if (ptr == NULL)
233 return xstrdup ("/"); 233 return xstrdup ("/");
234 234
235 copy = xmalloc (strlen (ptr) + 2); 235 ptrdiff_t len = strlen (ptr);
236 strcpy (copy, ptr); 236 copy = xmalloc (len + 2);
237 return strcat (copy, "/"); 237 strcpy (copy + len, "/");
238 return memcpy (copy, ptr, len);
238} 239}
239 240
240 241
@@ -334,6 +335,7 @@ get_user_app (const char *class)
334 return db; 335 return db;
335} 336}
336 337
338static char const xdefaults[] = ".Xdefaults";
337 339
338static XrmDatabase 340static XrmDatabase
339get_user_db (Display *display) 341get_user_db (Display *display)
@@ -351,16 +353,12 @@ get_user_db (Display *display)
351 db = XrmGetStringDatabase (xdefs); 353 db = XrmGetStringDatabase (xdefs);
352 else 354 else
353 { 355 {
354 char *home; 356 char *home = gethomedir ();
355 char *xdefault; 357 ptrdiff_t homelen = strlen (home);
356 358 char *filename = xrealloc (home, homelen + sizeof xdefaults);
357 home = gethomedir (); 359 strcpy (filename + homelen, xdefaults);
358 xdefault = xmalloc (strlen (home) + sizeof ".Xdefaults"); 360 db = XrmGetFileDatabase (filename);
359 strcpy (xdefault, home); 361 xfree (filename);
360 strcat (xdefault, ".Xdefaults");
361 db = XrmGetFileDatabase (xdefault);
362 xfree (home);
363 xfree (xdefault);
364 } 362 }
365 363
366#ifdef HAVE_XSCREENRESOURCESTRING 364#ifdef HAVE_XSCREENRESOURCESTRING
@@ -380,24 +378,22 @@ static XrmDatabase
380get_environ_db (void) 378get_environ_db (void)
381{ 379{
382 XrmDatabase db; 380 XrmDatabase db;
383 char *p; 381 char *p = getenv ("XENVIRONMENT");
384 char *path = 0; 382 char *filename = 0;
385 383
386 if ((p = getenv ("XENVIRONMENT")) == NULL) 384 if (!p)
387 { 385 {
388 static char const xdefaults[] = ".Xdefaults-";
389 char *home = gethomedir (); 386 char *home = gethomedir ();
390 char const *host = SSDATA (Vsystem_name); 387 ptrdiff_t homelen = strlen (home);
391 ptrdiff_t pathsize = (strlen (home) + sizeof xdefaults 388 ptrdiff_t filenamesize = (homelen + sizeof xdefaults
392 + SBYTES (Vsystem_name)); 389 + SBYTES (Vsystem_name));
393 path = xrealloc (home, pathsize); 390 p = filename = xrealloc (home, filenamesize);
394 strcat (strcat (path, xdefaults), host); 391 lispstpcpy (stpcpy (filename + homelen, xdefaults), Vsystem_name);
395 p = path;
396 } 392 }
397 393
398 db = XrmGetFileDatabase (p); 394 db = XrmGetFileDatabase (p);
399 395
400 xfree (path); 396 xfree (filename);
401 397
402 return db; 398 return db;
403} 399}
diff --git a/src/xsmfns.c b/src/xsmfns.c
index cd4f9ce57fa..8a835cf95f1 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -230,8 +230,7 @@ smc_save_yourself_CB (SmcConn smcConn,
230 props[props_idx]->vals[vp_idx++].value = emacs_program; 230 props[props_idx]->vals[vp_idx++].value = emacs_program;
231 231
232 smid_opt = xmalloc (strlen (SMID_OPT) + strlen (client_id) + 1); 232 smid_opt = xmalloc (strlen (SMID_OPT) + strlen (client_id) + 1);
233 strcpy (smid_opt, SMID_OPT); 233 strcpy (stpcpy (smid_opt, SMID_OPT), client_id);
234 strcat (smid_opt, client_id);
235 234
236 props[props_idx]->vals[vp_idx].length = strlen (smid_opt); 235 props[props_idx]->vals[vp_idx].length = strlen (smid_opt);
237 props[props_idx]->vals[vp_idx++].value = smid_opt; 236 props[props_idx]->vals[vp_idx++].value = smid_opt;
@@ -242,8 +241,7 @@ smc_save_yourself_CB (SmcConn smcConn,
242 if (cwd) 241 if (cwd)
243 { 242 {
244 chdir_opt = xmalloc (strlen (CHDIR_OPT) + strlen (cwd) + 1); 243 chdir_opt = xmalloc (strlen (CHDIR_OPT) + strlen (cwd) + 1);
245 strcpy (chdir_opt, CHDIR_OPT); 244 strcpy (stpcpy (chdir_opt, CHDIR_OPT), cwd);
246 strcat (chdir_opt, cwd);
247 245
248 props[props_idx]->vals[vp_idx].length = strlen (chdir_opt); 246 props[props_idx]->vals[vp_idx].length = strlen (chdir_opt);
249 props[props_idx]->vals[vp_idx++].value = chdir_opt; 247 props[props_idx]->vals[vp_idx++].value = chdir_opt;