aboutsummaryrefslogtreecommitdiffstats
path: root/lib-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 /lib-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 'lib-src')
-rw-r--r--lib-src/ebrowse.c29
-rw-r--r--lib-src/emacsclient.c35
-rw-r--r--lib-src/etags.c33
-rw-r--r--lib-src/pop.c3
-rw-r--r--lib-src/update-game-score.c12
5 files changed, 55 insertions, 57 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 29a88e85f02..b7431593c3e 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -1150,19 +1150,19 @@ sym_scope_1 (struct sym *p)
1150 if (*scope_buffer) 1150 if (*scope_buffer)
1151 { 1151 {
1152 ensure_scope_buffer_room (3); 1152 ensure_scope_buffer_room (3);
1153 strcat (scope_buffer, "::"); 1153 strcpy (scope_buffer + scope_buffer_len, "::");
1154 scope_buffer_len += 2; 1154 scope_buffer_len += 2;
1155 } 1155 }
1156 1156
1157 len = strlen (p->name); 1157 len = strlen (p->name);
1158 ensure_scope_buffer_room (len + 1); 1158 ensure_scope_buffer_room (len + 1);
1159 strcat (scope_buffer, p->name); 1159 strcpy (scope_buffer + scope_buffer_len, p->name);
1160 scope_buffer_len += len; 1160 scope_buffer_len += len;
1161 1161
1162 if (HAS_FLAG (p->flags, F_TEMPLATE)) 1162 if (HAS_FLAG (p->flags, F_TEMPLATE))
1163 { 1163 {
1164 ensure_scope_buffer_room (3); 1164 ensure_scope_buffer_room (3);
1165 strcat (scope_buffer, "<>"); 1165 strcpy (scope_buffer + scope_buffer_len, "<>");
1166 scope_buffer_len += 2; 1166 scope_buffer_len += 2;
1167 } 1167 }
1168 1168
@@ -2797,24 +2797,25 @@ operator_name (int *sc)
2797 s = token_string (LA1); 2797 s = token_string (LA1);
2798 MATCH (); 2798 MATCH ();
2799 2799
2800 len = strlen (s) + 10; 2800 ptrdiff_t slen = strlen (s);
2801 len = slen + 10;
2801 if (len > id_size) 2802 if (len > id_size)
2802 { 2803 {
2803 size_t new_size = max (len, 2 * id_size); 2804 size_t new_size = max (len, 2 * id_size);
2804 id = (char *) xrealloc (id, new_size); 2805 id = (char *) xrealloc (id, new_size);
2805 id_size = new_size; 2806 id_size = new_size;
2806 } 2807 }
2807 strcpy (id, s); 2808 char *z = stpcpy (id, s);
2808 2809
2809 /* Vector new or delete? */ 2810 /* Vector new or delete? */
2810 if (LOOKING_AT ('[')) 2811 if (LOOKING_AT ('['))
2811 { 2812 {
2812 strcat (id, "["); 2813 z = stpcpy (z, "[");
2813 MATCH (); 2814 MATCH ();
2814 2815
2815 if (LOOKING_AT (']')) 2816 if (LOOKING_AT (']'))
2816 { 2817 {
2817 strcat (id, "]"); 2818 strcpy (z, "]");
2818 MATCH (); 2819 MATCH ();
2819 } 2820 }
2820 } 2821 }
@@ -2830,7 +2831,7 @@ operator_name (int *sc)
2830 id = (char *) xrealloc (id, new_size); 2831 id = (char *) xrealloc (id, new_size);
2831 id_size = new_size; 2832 id_size = new_size;
2832 } 2833 }
2833 strcpy (id, "operator"); 2834 char *z = stpcpy (id, "operator");
2834 2835
2835 /* Beware access declarations of the form "X::f;" Beware of 2836 /* Beware access declarations of the form "X::f;" Beware of
2836 `operator () ()'. Yet another difficulty is found in 2837 `operator () ()'. Yet another difficulty is found in
@@ -2842,14 +2843,16 @@ operator_name (int *sc)
2842 len += strlen (s) + 2; 2843 len += strlen (s) + 2;
2843 if (len > id_size) 2844 if (len > id_size)
2844 { 2845 {
2846 ptrdiff_t idlen = z - id;
2845 size_t new_size = max (len, 2 * id_size); 2847 size_t new_size = max (len, 2 * id_size);
2846 id = (char *) xrealloc (id, new_size); 2848 id = (char *) xrealloc (id, new_size);
2847 id_size = new_size; 2849 id_size = new_size;
2850 z = id + idlen;
2848 } 2851 }
2849 2852
2850 if (*s != ')' && *s != ']') 2853 if (*s != ')' && *s != ']')
2851 strcat (id, " "); 2854 *z++ = ' ';
2852 strcat (id, s); 2855 z = stpcpy (z, s);
2853 MATCH (); 2856 MATCH ();
2854 2857
2855 /* If this is a simple operator like `+', stop now. */ 2858 /* If this is a simple operator like `+', stop now. */
@@ -3462,9 +3465,9 @@ open_file (char *file)
3462 buffer = (char *) xrealloc (buffer, buffer_size); 3465 buffer = (char *) xrealloc (buffer, buffer_size);
3463 } 3466 }
3464 3467
3465 strcpy (buffer, path->path); 3468 char *z = stpcpy (buffer, path->path);
3466 strcat (buffer, "/"); 3469 *z++ = '/';
3467 strcat (buffer, file); 3470 strcpy (z, file);
3468 fp = fopen (buffer, "r"); 3471 fp = fopen (buffer, "r");
3469 } 3472 }
3470 3473
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index ddc1b6de5e3..cfc321a1830 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -905,9 +905,9 @@ get_server_config (const char *config_file, struct sockaddr_in *server,
905 { 905 {
906 char *path = xmalloc (strlen (home) + strlen (config_file) 906 char *path = xmalloc (strlen (home) + strlen (config_file)
907 + EXTRA_SPACE); 907 + EXTRA_SPACE);
908 strcpy (path, home); 908 char *z = stpcpy (path, home);
909 strcat (path, "/.emacs.d/server/"); 909 z = stpcpy (z, "/.emacs.d/server/");
910 strcat (path, config_file); 910 strcpy (z, config_file);
911 config = fopen (path, "rb"); 911 config = fopen (path, "rb");
912 free (path); 912 free (path);
913 } 913 }
@@ -916,9 +916,9 @@ get_server_config (const char *config_file, struct sockaddr_in *server,
916 { 916 {
917 char *path = xmalloc (strlen (home) + strlen (config_file) 917 char *path = xmalloc (strlen (home) + strlen (config_file)
918 + EXTRA_SPACE); 918 + EXTRA_SPACE);
919 strcpy (path, home); 919 char *z = stpcpy (path, home);
920 strcat (path, "/.emacs.d/server/"); 920 z = stpcpy (z, "/.emacs.d/server/");
921 strcat (path, config_file); 921 strcpy (z, config_file);
922 config = fopen (path, "rb"); 922 config = fopen (path, "rb");
923 free (path); 923 free (path);
924 } 924 }
@@ -1193,7 +1193,6 @@ set_local_socket (const char *local_socket_name)
1193 { 1193 {
1194 /* socket_name is a file name component. */ 1194 /* socket_name is a file name component. */
1195 long uid = geteuid (); 1195 long uid = geteuid ();
1196 ptrdiff_t tmpdirlen;
1197 use_tmpdir = 1; 1196 use_tmpdir = 1;
1198 tmpdir = egetenv ("TMPDIR"); 1197 tmpdir = egetenv ("TMPDIR");
1199 if (!tmpdir) 1198 if (!tmpdir)
@@ -1212,12 +1211,11 @@ set_local_socket (const char *local_socket_name)
1212#endif 1211#endif
1213 tmpdir = "/tmp"; 1212 tmpdir = "/tmp";
1214 } 1213 }
1215 tmpdirlen = strlen (tmpdir);
1216 socket_name_storage = 1214 socket_name_storage =
1217 xmalloc (tmpdirlen + strlen (server_name) + EXTRA_SPACE); 1215 xmalloc (strlen (tmpdir) + strlen (server_name) + EXTRA_SPACE);
1218 strcpy (socket_name_storage, tmpdir); 1216 char *z = stpcpy (socket_name_storage, tmpdir);
1219 sprintf (socket_name_storage + tmpdirlen, "/emacs%ld/", uid); 1217 z += sprintf (z, "/emacs%ld/", uid);
1220 strcat (socket_name_storage + tmpdirlen, server_name); 1218 strcpy (z, server_name);
1221 local_socket_name = socket_name_storage; 1219 local_socket_name = socket_name_storage;
1222 } 1220 }
1223 1221
@@ -1253,12 +1251,12 @@ set_local_socket (const char *local_socket_name)
1253 { 1251 {
1254 /* We're running under su, apparently. */ 1252 /* We're running under su, apparently. */
1255 long uid = pw->pw_uid; 1253 long uid = pw->pw_uid;
1256 ptrdiff_t tmpdirlen = strlen (tmpdir);
1257 char *user_socket_name 1254 char *user_socket_name
1258 = xmalloc (tmpdirlen + strlen (server_name) + EXTRA_SPACE); 1255 = xmalloc (strlen (tmpdir) + strlen (server_name)
1259 strcpy (user_socket_name, tmpdir); 1256 + EXTRA_SPACE);
1260 sprintf (user_socket_name + tmpdirlen, "/emacs%ld/", uid); 1257 char *z = stpcpy (user_socket_name, tmpdir);
1261 strcat (user_socket_name + tmpdirlen, server_name); 1258 z += sprintf (z, "/emacs%ld/", uid);
1259 strcpy (z, server_name);
1262 1260
1263 if (strlen (user_socket_name) < sizeof (server.sun_path)) 1261 if (strlen (user_socket_name) < sizeof (server.sun_path))
1264 strcpy (server.sun_path, user_socket_name); 1262 strcpy (server.sun_path, user_socket_name);
@@ -1507,8 +1505,7 @@ start_daemon_and_retry_set_socket (void)
1507 const char *deq = "--daemon="; 1505 const char *deq = "--daemon=";
1508 char *daemon_arg = xmalloc (strlen (deq) 1506 char *daemon_arg = xmalloc (strlen (deq)
1509 + strlen (socket_name) + 1); 1507 + strlen (socket_name) + 1);
1510 strcpy (daemon_arg, deq); 1508 strcpy (stpcpy (daemon_arg, deq), socket_name);
1511 strcat (daemon_arg, socket_name);
1512 d_argv[1] = daemon_arg; 1509 d_argv[1] = daemon_arg;
1513 } 1510 }
1514 execvp ("emacs", d_argv); 1511 execvp ("emacs", d_argv);
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 6639ac4f235..78b3fed1128 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -1277,13 +1277,13 @@ main (int argc, char **argv)
1277 default: 1277 default:
1278 continue; /* the for loop */ 1278 continue; /* the for loop */
1279 } 1279 }
1280 strcpy (cmd, "mv "); 1280 char *z = stpcpy (cmd, "mv ");
1281 strcat (cmd, tagfile); 1281 z = stpcpy (z, tagfile);
1282 strcat (cmd, " OTAGS;fgrep -v '\t"); 1282 z = stpcpy (z, " OTAGS;fgrep -v '\t");
1283 strcat (cmd, argbuffer[i].what); 1283 z = stpcpy (z, argbuffer[i].what);
1284 strcat (cmd, "\t' OTAGS >"); 1284 z = stpcpy (z, "\t' OTAGS >");
1285 strcat (cmd, tagfile); 1285 z = stpcpy (z, tagfile);
1286 strcat (cmd, ";rm OTAGS"); 1286 strcpy (z, ";rm OTAGS");
1287 if (system (cmd) != EXIT_SUCCESS) 1287 if (system (cmd) != EXIT_SUCCESS)
1288 fatal ("failed to execute shell command", (char *)NULL); 1288 fatal ("failed to execute shell command", (char *)NULL);
1289 } 1289 }
@@ -1307,10 +1307,10 @@ main (int argc, char **argv)
1307 /* Maybe these should be used: 1307 /* Maybe these should be used:
1308 setenv ("LC_COLLATE", "C", 1); 1308 setenv ("LC_COLLATE", "C", 1);
1309 setenv ("LC_ALL", "C", 1); */ 1309 setenv ("LC_ALL", "C", 1); */
1310 strcpy (cmd, "sort -u -o "); 1310 char *z = stpcpy (cmd, "sort -u -o ");
1311 strcat (cmd, tagfile); 1311 z = stpcpy (z, tagfile);
1312 strcat (cmd, " "); 1312 *z++ = ' ';
1313 strcat (cmd, tagfile); 1313 strcpy (z, tagfile);
1314 exit (system (cmd)); 1314 exit (system (cmd));
1315 } 1315 }
1316 return EXIT_SUCCESS; 1316 return EXIT_SUCCESS;
@@ -3427,8 +3427,9 @@ C_entries (int c_ext, FILE *inf)
3427 case omethodtag: 3427 case omethodtag:
3428 case omethodparm: 3428 case omethodparm:
3429 objdef = omethodcolon; 3429 objdef = omethodcolon;
3430 linebuffer_setlen (&token_name, token_name.len + 1); 3430 int toklen = token_name.len;
3431 strcat (token_name.buffer, ":"); 3431 linebuffer_setlen (&token_name, toklen + 1);
3432 strcpy (token_name.buffer + toklen, ":");
3432 break; 3433 break;
3433 } 3434 }
3434 if (structdef == stagseen) 3435 if (structdef == stagseen)
@@ -6362,12 +6363,12 @@ relative_filename (char *file, char *dir)
6362 while ((dp = strchr (dp + 1, '/')) != NULL) 6363 while ((dp = strchr (dp + 1, '/')) != NULL)
6363 i += 1; 6364 i += 1;
6364 res = xnew (3*i + strlen (fp + 1) + 1, char); 6365 res = xnew (3*i + strlen (fp + 1) + 1, char);
6365 res[0] = '\0'; 6366 char *z = res;
6366 while (i-- > 0) 6367 while (i-- > 0)
6367 strcat (res, "../"); 6368 z = stpcpy (z, "../");
6368 6369
6369 /* Add the file name relative to the common root of file and dir. */ 6370 /* Add the file name relative to the common root of file and dir. */
6370 strcat (res, fp + 1); 6371 strcpy (z, fp + 1);
6371 free (afn); 6372 free (afn);
6372 6373
6373 return res; 6374 return res;
diff --git a/lib-src/pop.c b/lib-src/pop.c
index ffe16c5f911..70011504a34 100644
--- a/lib-src/pop.c
+++ b/lib-src/pop.c
@@ -1397,8 +1397,7 @@ sendline (popserver server, const char *line)
1397 over a few dozen messages, and is a big chunk of the time we 1397 over a few dozen messages, and is a big chunk of the time we
1398 spend fetching mail from a server close by. */ 1398 spend fetching mail from a server close by. */
1399 buf = alloca (strlen (line) + 3); 1399 buf = alloca (strlen (line) + 3);
1400 strcpy (buf, line); 1400 strcpy (stpcpy (buf, line), "\r\n");
1401 strcat (buf, "\r\n");
1402 ret = fullwrite (server->file, buf, strlen (buf)); 1401 ret = fullwrite (server->file, buf, strlen (buf));
1403 1402
1404 if (ret < 0) 1403 if (ret < 0)
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index 7a64cd04f47..b311001bd62 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -221,9 +221,9 @@ main (int argc, char **argv)
221 if (!scorefile) 221 if (!scorefile)
222 lose_syserr ("Couldn't allocate score file"); 222 lose_syserr ("Couldn't allocate score file");
223 223
224 strcpy (scorefile, prefix); 224 char *z = stpcpy (scorefile, prefix);
225 strcat (scorefile, "/"); 225 *z++ = '/';
226 strcat (scorefile, argv[optind]); 226 strcpy (z, argv[optind]);
227 227
228 newscore.score = normalize_integer (argv[optind + 1]); 228 newscore.score = normalize_integer (argv[optind + 1]);
229 if (! newscore.score) 229 if (! newscore.score)
@@ -430,8 +430,7 @@ write_scores (const char *filename, const struct score_entry *scores,
430 char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1); 430 char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1);
431 if (!tempfile) 431 if (!tempfile)
432 return -1; 432 return -1;
433 strcpy (tempfile, filename); 433 strcpy (stpcpy (tempfile, filename), ".tempXXXXXX");
434 strcat (tempfile, ".tempXXXXXX");
435 fd = mkostemp (tempfile, 0); 434 fd = mkostemp (tempfile, 0);
436 if (fd < 0) 435 if (fd < 0)
437 return -1; 436 return -1;
@@ -462,8 +461,7 @@ lock_file (const char *filename, void **state)
462 char *lockpath = malloc (strlen (filename) + strlen (lockext) + 60); 461 char *lockpath = malloc (strlen (filename) + strlen (lockext) + 60);
463 if (!lockpath) 462 if (!lockpath)
464 return -1; 463 return -1;
465 strcpy (lockpath, filename); 464 strcpy (stpcpy (lockpath, filename), lockext);
466 strcat (lockpath, lockext);
467 *state = lockpath; 465 *state = lockpath;
468 466
469 while ((fd = open (lockpath, O_CREAT | O_EXCL, 0600)) < 0) 467 while ((fd = open (lockpath, O_CREAT | O_EXCL, 0600)) < 0)