aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2011-09-05 13:43:14 -0700
committerPaul Eggert2011-09-05 13:43:14 -0700
commit1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67 (patch)
tree8c3e07779650c446922a93839c3ecdabb85cdaea
parentf4af5137d41b5ff71771028385f89be889dd1315 (diff)
parent697210c4822d4e7be9a81234d2026e5ace724a90 (diff)
downloademacs-1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67.tar.gz
emacs-1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67.zip
Merge from trunk.
-rw-r--r--ChangeLog4
-rw-r--r--autogen/config.in3
-rwxr-xr-xautogen/configure12
-rw-r--r--configure.in2
-rw-r--r--doc/emacs/ChangeLog4
-rw-r--r--doc/emacs/basic.texi4
-rw-r--r--etc/ChangeLog5
-rw-r--r--etc/grep.txt1
-rw-r--r--lib-src/ChangeLog35
-rw-r--r--lib-src/emacsclient.c95
-rw-r--r--lib-src/etags.c44
-rw-r--r--lib-src/movemail.c7
-rw-r--r--lib-src/update-game-score.c15
-rw-r--r--lisp/ChangeLog78
-rw-r--r--lisp/gnus/ChangeLog19
-rw-r--r--lisp/gnus/gnus-art.el4
-rw-r--r--lisp/gnus/gnus-score.el14
-rw-r--r--lisp/gnus/gnus-spec.el58
-rw-r--r--lisp/gnus/gnus.el7
-rw-r--r--lisp/gnus/nnimap.el3
-rw-r--r--lisp/help.el2
-rw-r--r--lisp/mail/rmail.el2
-rw-r--r--lisp/mail/rmailmm.el4
-rw-r--r--lisp/mail/sendmail.el90
-rw-r--r--lisp/mail/smtpmail.el2
-rw-r--r--lisp/net/rcirc.el22
-rw-r--r--lisp/net/tramp-sh.el172
-rw-r--r--lisp/net/tramp.el94
-rw-r--r--lisp/progmodes/grep.el19
-rw-r--r--lisp/progmodes/python.el12
-rw-r--r--lisp/subr.el2
-rw-r--r--lisp/window.el48
-rw-r--r--nt/ChangeLog4
-rw-r--r--nt/config.nt1
-rw-r--r--src/ChangeLog154
-rw-r--r--src/dbusbind.c69
-rw-r--r--src/dispnew.c19
-rw-r--r--src/doprnt.c203
-rw-r--r--src/editfns.c5
-rw-r--r--src/emacs.c16
-rw-r--r--src/eval.c26
-rw-r--r--src/filelock.c35
-rw-r--r--src/font.c203
-rw-r--r--src/fontset.c6
-rw-r--r--src/frame.c46
-rw-r--r--src/gtkutil.c5
-rw-r--r--src/indent.c12
-rw-r--r--src/keyboard.c46
-rw-r--r--src/keymap.c19
-rw-r--r--src/lisp.h12
-rw-r--r--src/lread.c16
-rw-r--r--src/macros.c12
-rw-r--r--src/macros.h3
-rw-r--r--src/minibuf.c8
-rw-r--r--src/nsterm.m2
-rw-r--r--src/print.c37
-rw-r--r--src/process.c6
-rw-r--r--src/search.c10
-rw-r--r--src/sysdep.c39
-rw-r--r--src/term.c2
-rw-r--r--src/window.c28
-rw-r--r--src/window.h4
-rw-r--r--src/xdisp.c4
-rw-r--r--src/xfaces.c35
-rw-r--r--src/xfns.c2
-rw-r--r--src/xml.c1
-rw-r--r--src/xterm.c3
-rw-r--r--src/xterm.h3
68 files changed, 1320 insertions, 659 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f38dbf71ca..aae3e190049 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
12011-09-04 Paul Eggert <eggert@cs.ucla.edu>
2
3 * configure.in (snprintf): New check.
4
12011-08-30 Paul Eggert <eggert@cs.ucla.edu> 52011-08-30 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 * configure.in (opsys): Change pattern to *-*-linux* 7 * configure.in (opsys): Change pattern to *-*-linux*
diff --git a/autogen/config.in b/autogen/config.in
index 24dd54db43f..5a53b240ef8 100644
--- a/autogen/config.in
+++ b/autogen/config.in
@@ -672,6 +672,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
672/* Define to 1 if the system has the type `sigset_t'. */ 672/* Define to 1 if the system has the type `sigset_t'. */
673#undef HAVE_SIGSET_T 673#undef HAVE_SIGSET_T
674 674
675/* Define to 1 if you have the `snprintf' function. */
676#undef HAVE_SNPRINTF
677
675/* Define to 1 if you have sound support. */ 678/* Define to 1 if you have sound support. */
676#undef HAVE_SOUND 679#undef HAVE_SOUND
677 680
diff --git a/autogen/configure b/autogen/configure
index bbd54f57153..8d010ddf7b7 100755
--- a/autogen/configure
+++ b/autogen/configure
@@ -15312,6 +15312,18 @@ $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h
15312fi 15312fi
15313 15313
15314 15314
15315for ac_func in snprintf
15316do :
15317 ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf"
15318if test "x$ac_cv_func_snprintf" = x""yes; then :
15319 cat >>confdefs.h <<_ACEOF
15320#define HAVE_SNPRINTF 1
15321_ACEOF
15322
15323fi
15324done
15325
15326
15315{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5 15327{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for nl_langinfo and CODESET" >&5
15316$as_echo_n "checking for nl_langinfo and CODESET... " >&6; } 15328$as_echo_n "checking for nl_langinfo and CODESET... " >&6; }
15317if test "${emacs_cv_langinfo_codeset+set}" = set; then : 15329if test "${emacs_cv_langinfo_codeset+set}" = set; then :
diff --git a/configure.in b/configure.in
index 715e8278df2..dcc2bdb99d1 100644
--- a/configure.in
+++ b/configure.in
@@ -3071,6 +3071,8 @@ fi
3071 3071
3072AC_FUNC_FORK 3072AC_FUNC_FORK
3073 3073
3074AC_CHECK_FUNCS(snprintf)
3075
3074dnl Adapted from Haible's version. 3076dnl Adapted from Haible's version.
3075AC_CACHE_CHECK([for nl_langinfo and CODESET], emacs_cv_langinfo_codeset, 3077AC_CACHE_CHECK([for nl_langinfo and CODESET], emacs_cv_langinfo_codeset,
3076 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]], 3078 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <langinfo.h>]],
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index 2407d7dd18f..56958417300 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,7 @@
12011-09-04 Eli Zaretskii <eliz@gnu.org>
2
3 * basic.texi (Inserting Text): Add index entries. (Bug#9433)
4
12011-08-29 Chong Yidong <cyd@stupidchicken.com> 52011-08-29 Chong Yidong <cyd@stupidchicken.com>
2 6
3 * modes.texi (Choosing Modes): auto-mode-case-fold is now t. 7 * modes.texi (Choosing Modes): auto-mode-case-fold is now t.
diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi
index edf07859e52..b06391f004c 100644
--- a/doc/emacs/basic.texi
+++ b/doc/emacs/basic.texi
@@ -101,7 +101,9 @@ character to insert (@pxref{Arguments}).
101 101
102@findex ucs-insert 102@findex ucs-insert
103@kindex C-x 8 RET 103@kindex C-x 8 RET
104@cindex Unicode 104@cindex Unicode characters, inserting
105@cindex insert Unicode character
106@cindex characters, inserting by name or code-point
105 Instead of @kbd{C-q}, you can use @kbd{C-x 8 @key{RET}} 107 Instead of @kbd{C-q}, you can use @kbd{C-x 8 @key{RET}}
106(@code{ucs-insert}) to insert a character based on its Unicode name or 108(@code{ucs-insert}) to insert a character based on its Unicode name or
107code-point. This command prompts for a character to insert, using 109code-point. This command prompts for a character to insert, using
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 24c0fd54422..0749862f676 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,8 @@
12011-09-05 Juri Linkov <juri@jurta.org>
2
3 * grep.txt: Add `eval' to the Local Variables section that
4 emulates `grep-filter'.
5
12011-08-30 Paul Eggert <eggert@cs.ucla.edu> 62011-08-30 Paul Eggert <eggert@cs.ucla.edu>
2 7
3 * MACHINES: Remove obsolete info and update a bit (Bug#9404). 8 * MACHINES: Remove obsolete info and update a bit (Bug#9404).
diff --git a/etc/grep.txt b/etc/grep.txt
index 9a3159f6b08..01ffa9f3ef8 100644
--- a/etc/grep.txt
+++ b/etc/grep.txt
@@ -103,5 +103,6 @@ COPYING PERMISSIONS:
103 103
104 104
105;;; Local Variables: 105;;; Local Variables:
106;;; eval: (let ((inhibit-read-only t) (compilation-filter-start (point-min))) (save-excursion (goto-char (point-max)) (grep-filter) (set-buffer-modified-p nil)))
106;;; buffer-read-only: t 107;;; buffer-read-only: t
107;;; End: 108;;; End:
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index c878d313b70..9041eae8bbe 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,38 @@
12011-09-04 Paul Eggert <eggert@cs.ucla.edu>
2
3 Integer and memory overflow issues (Bug#9397).
4
5 * emacsclient.c (xmalloc): Accept size_t, not unsigned int, to
6 avoid potential buffer overflow issues on typical 64-bit hosts.
7 Return void *, not long *.
8 (get_current_dir_name): Report a failure, instead of looping
9 forever, if buffer size calculation overflows. Treat malloc
10 failures like realloc failures, as that has better behavior and is
11 more consistent. Do not check whether xmalloc returns NULL, as
12 that's not possible.
13 (message): Do not arbitrarily truncate message to 2048 bytes when
14 sending it to stderr; use vfprintf instead.
15 (get_server_config, set_local_socket)
16 (start_daemon_and_retry_set_socket): Do not alloca
17 arbitrarily-large buffers; that's not safe.
18 (get_server_config, set_local_socket): Do not use sprintf when its
19 result might not fit in 'int'.
20 (set_local_socket): Do not assume uid fits in 'int'.
21
22 * etags.c (xmalloc, xrealloc): Accept size_t, not unsigned int,
23 to avoid potential buffer overflow issues on typical 64-bit hosts.
24 (whatlen_max): New static var.
25 (main): Avoid buffer overflow if subsidiary command length is
26 greater than BUFSIZ or 2*BUFSIZ + 20. Do not use sprintf when its
27 result might not fit in 'int'.
28
29 * movemail.c (main): Do not use sprintf when its result might not fit
30 in 'int'. Instead, put the possibly-long file name into the
31 output of pfatal_with_name.
32
33 * update-game-score.c: Include <limits.h>
34 (get_user_id): Do not assume uid fits in 'int'. Simplify.
35
12011-07-28 Paul Eggert <eggert@cs.ucla.edu> 362011-07-28 Paul Eggert <eggert@cs.ucla.edu>
2 37
3 Assume freestanding C89 headers, string.h, stdlib.h. 38 Assume freestanding C89 headers, string.h, stdlib.h.
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 2af139aee6d..ece9dc65c49 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -194,10 +194,10 @@ struct option longopts[] =
194 194
195/* Like malloc but get fatal error if memory is exhausted. */ 195/* Like malloc but get fatal error if memory is exhausted. */
196 196
197static long * 197static void *
198xmalloc (unsigned int size) 198xmalloc (size_t size)
199{ 199{
200 long *result = (long *) malloc (size); 200 void *result = malloc (size);
201 if (result == NULL) 201 if (result == NULL)
202 { 202 {
203 perror ("malloc"); 203 perror ("malloc");
@@ -250,32 +250,33 @@ get_current_dir_name (void)
250 ) 250 )
251 { 251 {
252 buf = (char *) xmalloc (strlen (pwd) + 1); 252 buf = (char *) xmalloc (strlen (pwd) + 1);
253 if (!buf)
254 return NULL;
255 strcpy (buf, pwd); 253 strcpy (buf, pwd);
256 } 254 }
257#ifdef HAVE_GETCWD 255#ifdef HAVE_GETCWD
258 else 256 else
259 { 257 {
260 size_t buf_size = 1024; 258 size_t buf_size = 1024;
261 buf = (char *) xmalloc (buf_size);
262 if (!buf)
263 return NULL;
264 for (;;) 259 for (;;)
265 { 260 {
261 int tmp_errno;
262 buf = malloc (buf_size);
263 if (! buf)
264 break;
266 if (getcwd (buf, buf_size) == buf) 265 if (getcwd (buf, buf_size) == buf)
267 break; 266 break;
268 if (errno != ERANGE) 267 tmp_errno = errno;
268 free (buf);
269 if (tmp_errno != ERANGE)
269 { 270 {
270 int tmp_errno = errno;
271 free (buf);
272 errno = tmp_errno; 271 errno = tmp_errno;
273 return NULL; 272 return NULL;
274 } 273 }
275 buf_size *= 2; 274 buf_size *= 2;
276 buf = (char *) realloc (buf, buf_size); 275 if (! buf_size)
277 if (!buf) 276 {
278 return NULL; 277 errno = ENOMEM;
278 return NULL;
279 }
279 } 280 }
280 } 281 }
281#else 282#else
@@ -283,8 +284,6 @@ get_current_dir_name (void)
283 { 284 {
284 /* We need MAXPATHLEN here. */ 285 /* We need MAXPATHLEN here. */
285 buf = (char *) xmalloc (MAXPATHLEN + 1); 286 buf = (char *) xmalloc (MAXPATHLEN + 1);
286 if (!buf)
287 return NULL;
288 if (getwd (buf) == NULL) 287 if (getwd (buf) == NULL)
289 { 288 {
290 int tmp_errno = errno; 289 int tmp_errno = errno;
@@ -494,16 +493,17 @@ static void message (int, const char *, ...) ATTRIBUTE_FORMAT_PRINTF (2, 3);
494static void 493static void
495message (int is_error, const char *format, ...) 494message (int is_error, const char *format, ...)
496{ 495{
497 char msg[2048];
498 va_list args; 496 va_list args;
499 497
500 va_start (args, format); 498 va_start (args, format);
501 vsprintf (msg, format, args);
502 va_end (args);
503 499
504#ifdef WINDOWSNT 500#ifdef WINDOWSNT
505 if (w32_window_app ()) 501 if (w32_window_app ())
506 { 502 {
503 char msg[2048];
504 vsnprintf (msg, sizeof msg, format, args);
505 msg[sizeof msg - 1] = '\0';
506
507 if (is_error) 507 if (is_error)
508 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR); 508 MessageBox (NULL, msg, "Emacsclient ERROR", MB_ICONERROR);
509 else 509 else
@@ -514,9 +514,11 @@ message (int is_error, const char *format, ...)
514 { 514 {
515 FILE *f = is_error ? stderr : stdout; 515 FILE *f = is_error ? stderr : stdout;
516 516
517 fputs (msg, f); 517 vfprintf (f, format, args);
518 fflush (f); 518 fflush (f);
519 } 519 }
520
521 va_end (args);
520} 522}
521 523
522/* Decode the options from argv and argc. 524/* Decode the options from argv and argc.
@@ -959,18 +961,24 @@ get_server_config (struct sockaddr_in *server, char *authentication)
959 961
960 if (home) 962 if (home)
961 { 963 {
962 char *path = alloca (strlen (home) + strlen (server_file) 964 char *path = xmalloc (strlen (home) + strlen (server_file)
963 + EXTRA_SPACE); 965 + EXTRA_SPACE);
964 sprintf (path, "%s/.emacs.d/server/%s", home, server_file); 966 strcpy (path, home);
967 strcat (path, "/.emacs.d/server/");
968 strcat (path, server_file);
965 config = fopen (path, "rb"); 969 config = fopen (path, "rb");
970 free (path);
966 } 971 }
967#ifdef WINDOWSNT 972#ifdef WINDOWSNT
968 if (!config && (home = egetenv ("APPDATA"))) 973 if (!config && (home = egetenv ("APPDATA")))
969 { 974 {
970 char *path = alloca (strlen (home) + strlen (server_file) 975 char *path = xmalloc (strlen (home) + strlen (server_file)
971 + EXTRA_SPACE); 976 + EXTRA_SPACE);
972 sprintf (path, "%s/.emacs.d/server/%s", home, server_file); 977 strcpy (path, home);
978 strcat (path, "/.emacs.d/server/");
979 strcat (path, server_file);
973 config = fopen (path, "rb"); 980 config = fopen (path, "rb");
981 free (path);
974 } 982 }
975#endif 983#endif
976 } 984 }
@@ -1243,6 +1251,8 @@ set_local_socket (void)
1243 int saved_errno = 0; 1251 int saved_errno = 0;
1244 const char *server_name = "server"; 1252 const char *server_name = "server";
1245 const char *tmpdir IF_LINT ( = NULL); 1253 const char *tmpdir IF_LINT ( = NULL);
1254 char *tmpdir_storage = NULL;
1255 char *socket_name_storage = NULL;
1246 1256
1247 if (socket_name && !strchr (socket_name, '/') 1257 if (socket_name && !strchr (socket_name, '/')
1248 && !strchr (socket_name, '\\')) 1258 && !strchr (socket_name, '\\'))
@@ -1255,6 +1265,8 @@ set_local_socket (void)
1255 1265
1256 if (default_sock) 1266 if (default_sock)
1257 { 1267 {
1268 long uid = geteuid ();
1269 ptrdiff_t tmpdirlen;
1258 tmpdir = egetenv ("TMPDIR"); 1270 tmpdir = egetenv ("TMPDIR");
1259 if (!tmpdir) 1271 if (!tmpdir)
1260 { 1272 {
@@ -1265,17 +1277,19 @@ set_local_socket (void)
1265 size_t n = confstr (_CS_DARWIN_USER_TEMP_DIR, NULL, (size_t) 0); 1277 size_t n = confstr (_CS_DARWIN_USER_TEMP_DIR, NULL, (size_t) 0);
1266 if (n > 0) 1278 if (n > 0)
1267 { 1279 {
1268 tmpdir = alloca (n); 1280 tmpdir = tmpdir_storage = xmalloc (n);
1269 confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir, n); 1281 confstr (_CS_DARWIN_USER_TEMP_DIR, tmpdir, n);
1270 } 1282 }
1271 else 1283 else
1272#endif 1284#endif
1273 tmpdir = "/tmp"; 1285 tmpdir = "/tmp";
1274 } 1286 }
1275 socket_name = alloca (strlen (tmpdir) + strlen (server_name) 1287 tmpdirlen = strlen (tmpdir);
1276 + EXTRA_SPACE); 1288 socket_name = socket_name_storage =
1277 sprintf (socket_name, "%s/emacs%d/%s", 1289 xmalloc (tmpdirlen + strlen (server_name) + EXTRA_SPACE);
1278 tmpdir, (int) geteuid (), server_name); 1290 strcpy (socket_name, tmpdir);
1291 sprintf (socket_name + tmpdirlen, "/emacs%ld/", uid);
1292 strcat (socket_name + tmpdirlen, server_name);
1279 } 1293 }
1280 1294
1281 if (strlen (socket_name) < sizeof (server.sun_path)) 1295 if (strlen (socket_name) < sizeof (server.sun_path))
@@ -1309,10 +1323,13 @@ set_local_socket (void)
1309 if (pw && (pw->pw_uid != geteuid ())) 1323 if (pw && (pw->pw_uid != geteuid ()))
1310 { 1324 {
1311 /* We're running under su, apparently. */ 1325 /* We're running under su, apparently. */
1312 socket_name = alloca (strlen (tmpdir) + strlen (server_name) 1326 long uid = pw->pw_uid;
1313 + EXTRA_SPACE); 1327 ptrdiff_t tmpdirlen = strlen (tmpdir);
1314 sprintf (socket_name, "%s/emacs%d/%s", 1328 socket_name = xmalloc (tmpdirlen + strlen (server_name)
1315 tmpdir, (int) pw->pw_uid, server_name); 1329 + EXTRA_SPACE);
1330 strcpy (socket_name, tmpdir);
1331 sprintf (socket_name + tmpdirlen, "/emacs%ld/", uid);
1332 strcat (socket_name + tmpdirlen, server_name);
1316 1333
1317 if (strlen (socket_name) < sizeof (server.sun_path)) 1334 if (strlen (socket_name) < sizeof (server.sun_path))
1318 strcpy (server.sun_path, socket_name); 1335 strcpy (server.sun_path, socket_name);
@@ -1322,6 +1339,7 @@ set_local_socket (void)
1322 progname, socket_name); 1339 progname, socket_name);
1323 exit (EXIT_FAILURE); 1340 exit (EXIT_FAILURE);
1324 } 1341 }
1342 free (socket_name);
1325 1343
1326 sock_status = socket_status (server.sun_path); 1344 sock_status = socket_status (server.sun_path);
1327 saved_errno = errno; 1345 saved_errno = errno;
@@ -1331,6 +1349,9 @@ set_local_socket (void)
1331 } 1349 }
1332 } 1350 }
1333 1351
1352 free (socket_name_storage);
1353 free (tmpdir_storage);
1354
1334 switch (sock_status) 1355 switch (sock_status)
1335 { 1356 {
1336 case 1: 1357 case 1:
@@ -1526,8 +1547,8 @@ start_daemon_and_retry_set_socket (void)
1526 { 1547 {
1527 /* Pass --daemon=socket_name as argument. */ 1548 /* Pass --daemon=socket_name as argument. */
1528 const char *deq = "--daemon="; 1549 const char *deq = "--daemon=";
1529 char *daemon_arg = alloca (strlen (deq) 1550 char *daemon_arg = xmalloc (strlen (deq)
1530 + strlen (socket_name) + 1); 1551 + strlen (socket_name) + 1);
1531 strcpy (daemon_arg, deq); 1552 strcpy (daemon_arg, deq);
1532 strcat (daemon_arg, socket_name); 1553 strcat (daemon_arg, socket_name);
1533 d_argv[1] = daemon_arg; 1554 d_argv[1] = daemon_arg;
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 522c54ee4a5..9d920565804 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -414,8 +414,8 @@ static bool filename_is_absolute (char *f);
414static void canonicalize_filename (char *); 414static void canonicalize_filename (char *);
415static void linebuffer_init (linebuffer *); 415static void linebuffer_init (linebuffer *);
416static void linebuffer_setlen (linebuffer *, int); 416static void linebuffer_setlen (linebuffer *, int);
417static PTR xmalloc (unsigned int); 417static PTR xmalloc (size_t);
418static PTR xrealloc (char *, unsigned int); 418static PTR xrealloc (char *, size_t);
419 419
420 420
421static char searchar = '/'; /* use /.../ searches */ 421static char searchar = '/'; /* use /.../ searches */
@@ -425,6 +425,7 @@ static char *progname; /* name this program was invoked with */
425static char *cwd; /* current working directory */ 425static char *cwd; /* current working directory */
426static char *tagfiledir; /* directory of tagfile */ 426static char *tagfiledir; /* directory of tagfile */
427static FILE *tagf; /* ioptr for tags file */ 427static FILE *tagf; /* ioptr for tags file */
428static ptrdiff_t whatlen_max; /* maximum length of any 'what' member */
428 429
429static fdesc *fdhead; /* head of file description list */ 430static fdesc *fdhead; /* head of file description list */
430static fdesc *curfdp; /* current file description */ 431static fdesc *curfdp; /* current file description */
@@ -1066,6 +1067,7 @@ main (int argc, char **argv)
1066 int current_arg, file_count; 1067 int current_arg, file_count;
1067 linebuffer filename_lb; 1068 linebuffer filename_lb;
1068 bool help_asked = FALSE; 1069 bool help_asked = FALSE;
1070 ptrdiff_t len;
1069 char *optstring; 1071 char *optstring;
1070 int opt; 1072 int opt;
1071 1073
@@ -1110,6 +1112,9 @@ main (int argc, char **argv)
1110 /* This means that a file name has been seen. Record it. */ 1112 /* This means that a file name has been seen. Record it. */
1111 argbuffer[current_arg].arg_type = at_filename; 1113 argbuffer[current_arg].arg_type = at_filename;
1112 argbuffer[current_arg].what = optarg; 1114 argbuffer[current_arg].what = optarg;
1115 len = strlen (optarg);
1116 if (whatlen_max < len)
1117 whatlen_max = len;
1113 ++current_arg; 1118 ++current_arg;
1114 ++file_count; 1119 ++file_count;
1115 break; 1120 break;
@@ -1118,6 +1123,9 @@ main (int argc, char **argv)
1118 /* Parse standard input. Idea by Vivek <vivek@etla.org>. */ 1123 /* Parse standard input. Idea by Vivek <vivek@etla.org>. */
1119 argbuffer[current_arg].arg_type = at_stdin; 1124 argbuffer[current_arg].arg_type = at_stdin;
1120 argbuffer[current_arg].what = optarg; 1125 argbuffer[current_arg].what = optarg;
1126 len = strlen (optarg);
1127 if (whatlen_max < len)
1128 whatlen_max = len;
1121 ++current_arg; 1129 ++current_arg;
1122 ++file_count; 1130 ++file_count;
1123 if (parsing_stdin) 1131 if (parsing_stdin)
@@ -1160,6 +1168,9 @@ main (int argc, char **argv)
1160 case 'r': 1168 case 'r':
1161 argbuffer[current_arg].arg_type = at_regexp; 1169 argbuffer[current_arg].arg_type = at_regexp;
1162 argbuffer[current_arg].what = optarg; 1170 argbuffer[current_arg].what = optarg;
1171 len = strlen (optarg);
1172 if (whatlen_max < len)
1173 whatlen_max = len;
1163 ++current_arg; 1174 ++current_arg;
1164 break; 1175 break;
1165 case 'R': 1176 case 'R':
@@ -1198,6 +1209,9 @@ main (int argc, char **argv)
1198 { 1209 {
1199 argbuffer[current_arg].arg_type = at_filename; 1210 argbuffer[current_arg].arg_type = at_filename;
1200 argbuffer[current_arg].what = argv[optind]; 1211 argbuffer[current_arg].what = argv[optind];
1212 len = strlen (argv[optind]);
1213 if (whatlen_max < len)
1214 whatlen_max = len;
1201 ++current_arg; 1215 ++current_arg;
1202 ++file_count; 1216 ++file_count;
1203 } 1217 }
@@ -1331,7 +1345,9 @@ main (int argc, char **argv)
1331 /* From here on, we are in (CTAGS && !cxref_style) */ 1345 /* From here on, we are in (CTAGS && !cxref_style) */
1332 if (update) 1346 if (update)
1333 { 1347 {
1334 char cmd[BUFSIZ]; 1348 char *cmd =
1349 xmalloc (strlen (tagfile) + whatlen_max +
1350 sizeof "mv..OTAGS;fgrep -v '\t\t' OTAGS >;rm OTAGS");
1335 for (i = 0; i < current_arg; ++i) 1351 for (i = 0; i < current_arg; ++i)
1336 { 1352 {
1337 switch (argbuffer[i].arg_type) 1353 switch (argbuffer[i].arg_type)
@@ -1342,12 +1358,17 @@ main (int argc, char **argv)
1342 default: 1358 default:
1343 continue; /* the for loop */ 1359 continue; /* the for loop */
1344 } 1360 }
1345 sprintf (cmd, 1361 strcpy (cmd, "mv ");
1346 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS", 1362 strcat (cmd, tagfile);
1347 tagfile, argbuffer[i].what, tagfile); 1363 strcat (cmd, " OTAGS;fgrep -v '\t");
1364 strcat (cmd, argbuffer[i].what);
1365 strcat (cmd, "\t' OTAGS >");
1366 strcat (cmd, tagfile);
1367 strcat (cmd, ";rm OTAGS");
1348 if (system (cmd) != EXIT_SUCCESS) 1368 if (system (cmd) != EXIT_SUCCESS)
1349 fatal ("failed to execute shell command", (char *)NULL); 1369 fatal ("failed to execute shell command", (char *)NULL);
1350 } 1370 }
1371 free (cmd);
1351 append_to_tagfile = TRUE; 1372 append_to_tagfile = TRUE;
1352 } 1373 }
1353 1374
@@ -1363,11 +1384,14 @@ main (int argc, char **argv)
1363 if (CTAGS) 1384 if (CTAGS)
1364 if (append_to_tagfile || update) 1385 if (append_to_tagfile || update)
1365 { 1386 {
1366 char cmd[2*BUFSIZ+20]; 1387 char *cmd = xmalloc (2 * strlen (tagfile) + sizeof "sort -u -o..");
1367 /* Maybe these should be used: 1388 /* Maybe these should be used:
1368 setenv ("LC_COLLATE", "C", 1); 1389 setenv ("LC_COLLATE", "C", 1);
1369 setenv ("LC_ALL", "C", 1); */ 1390 setenv ("LC_ALL", "C", 1); */
1370 sprintf (cmd, "sort -u -o %.*s %.*s", BUFSIZ, tagfile, BUFSIZ, tagfile); 1391 strcpy (cmd, "sort -u -o ");
1392 strcat (cmd, tagfile);
1393 strcat (cmd, " ");
1394 strcat (cmd, tagfile);
1371 exit (system (cmd)); 1395 exit (system (cmd));
1372 } 1396 }
1373 return EXIT_SUCCESS; 1397 return EXIT_SUCCESS;
@@ -6656,7 +6680,7 @@ linebuffer_setlen (linebuffer *lbp, int toksize)
6656 6680
6657/* Like malloc but get fatal error if memory is exhausted. */ 6681/* Like malloc but get fatal error if memory is exhausted. */
6658static PTR 6682static PTR
6659xmalloc (unsigned int size) 6683xmalloc (size_t size)
6660{ 6684{
6661 PTR result = (PTR) malloc (size); 6685 PTR result = (PTR) malloc (size);
6662 if (result == NULL) 6686 if (result == NULL)
@@ -6665,7 +6689,7 @@ xmalloc (unsigned int size)
6665} 6689}
6666 6690
6667static PTR 6691static PTR
6668xrealloc (char *ptr, unsigned int size) 6692xrealloc (char *ptr, size_t size)
6669{ 6693{
6670 PTR result = (PTR) realloc (ptr, size); 6694 PTR result = (PTR) realloc (ptr, size);
6671 if (result == NULL) 6695 if (result == NULL)
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index d70c655adec..097bf23c202 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -325,11 +325,10 @@ main (int argc, char **argv)
325 if (desc < 0) 325 if (desc < 0)
326 { 326 {
327 int mkstemp_errno = errno; 327 int mkstemp_errno = errno;
328 char *message = (char *) xmalloc (strlen (tempname) + 50); 328 error ("error while creating what would become the lock file",
329 sprintf (message, "creating %s, which would become the lock file", 329 0, 0);
330 tempname);
331 errno = mkstemp_errno; 330 errno = mkstemp_errno;
332 pfatal_with_name (message); 331 pfatal_with_name (tempname);
333 } 332 }
334 close (desc); 333 close (desc);
335 334
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index 2a89379aefe..9fba51a33de 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -35,6 +35,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 35
36#include <unistd.h> 36#include <unistd.h>
37#include <errno.h> 37#include <errno.h>
38#include <limits.h>
38#include <string.h> 39#include <string.h>
39#include <stdlib.h> 40#include <stdlib.h>
40#include <stdio.h> 41#include <stdio.h>
@@ -128,19 +129,13 @@ lose_syserr (const char *msg)
128static char * 129static char *
129get_user_id (void) 130get_user_id (void)
130{ 131{
131 char *name;
132 struct passwd *buf = getpwuid (getuid ()); 132 struct passwd *buf = getpwuid (getuid ());
133 if (!buf) 133 if (!buf)
134 { 134 {
135 int count = 1; 135 long uid = getuid ();
136 int uid = (int) getuid (); 136 char *name = malloc (sizeof uid * CHAR_BIT / 3 + 1);
137 int tuid = uid; 137 if (name)
138 while (tuid /= 10) 138 sprintf (name, "%ld", uid);
139 count++;
140 name = malloc (count+1);
141 if (!name)
142 return NULL;
143 sprintf (name, "%d", uid);
144 return name; 139 return name;
145 } 140 }
146 return buf->pw_name; 141 return buf->pw_name;
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 599c383ef13..7a922e002d7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,81 @@
12011-09-05 Oleksandr Gavenko <gavenkoa@gmail.com> (tiny change)
2
3 * progmodes/grep.el (rgrep): Add "-type d" (bug#9414).
4
52011-09-05 Juri Linkov <juri@jurta.org>
6
7 * progmodes/grep.el (grep-process-setup): Fix comments (bug#8084).
8
92011-09-05 Juri Linkov <juri@jurta.org>
10
11 * progmodes/grep.el (grep-filter): Avoid incomplete processing by
12 keeping point where processing of grep matches begins, and
13 continue to delete remaining escape sequences from the same point.
14 (grep-filter): Make leading zero optional in "0?1;31m" because
15 git-grep emits "\033[1;31m" escape sequences unlike expected
16 "\033[01;31m" as GNU Grep does (bug#9408).
17 (grep-process-setup): Replace obsolete "ml=" with newer "sl=".
18
192011-09-05 Juri Linkov <juri@jurta.org>
20
21 * subr.el (y-or-n-p): Capitalize "yes".
22
232011-09-04 Michael Albinus <michael.albinus@gmx.de>
24
25 * net/tramp.el (top): Require 'shell. Use `tramp-unload-hook' but
26 `tramp-cache-unload-hook' where appropriate.
27 (tramp-methods): Rename `tramp-remote-sh' to
28 `tramp-remote-shell'. Add `tramp-remote-shell-args'.
29 (tramp-handle-shell-command): New defun, moved from tramp-sh.el.
30
31 * net/tramp-sh.el (top): Don't require 'shell.
32 (tramp-methods): Add `tramp-remote-shell' and
33 `tramp-remote-shell-args' entries.
34 (tramp-sh-file-name-handler-alist): Use `tramp-handle-shell-command'.
35 (tramp-sh-handle-shell-command): Remove.
36 (tramp-find-shell, tramp-open-connection-setup-interactive-shell):
37 Use `tramp-remote-shell'.
38
392011-09-03 Chong Yidong <cyd@stupidchicken.com>
40
41 * mail/sendmail.el (sendmail-query-once-function): Deleted.
42 (sendmail-query-once): Save directly to send-mail-function.
43 Update message-send-mail-function too.
44
45 * mail/smtpmail.el (smtpmail-try-auth-methods): Clarify prompt.
46
472011-09-03 Christoph Scholtes <cschol2112@googlemail.com>
48
49 * progmodes/python.el (python-mode-map): Use correct function to
50 start python interpreter from menu-bar (as reported by Geert
51 Kloosterman).
52 (inferior-python-mode-map): Fix typo.
53 (python-shell-map): Removed.
54
552011-09-03 Deniz Dogan <deniz@dogan.se>
56
57 * net/rcirc.el (rcirc-print): Simplify code for
58 rcirc-scroll-show-maximum-output. There is no need to walk
59 through all windows to find the right one.
60
612011-09-03 Christoph Scholtes <cschol2112@googlemail.com>
62
63 * help.el (help-return-method): Doc fix.
64
652011-09-03 Martin Rudalics <rudalics@gmx.at>
66
67 * window.el (window-deletable-p): Don't return a non-nil value
68 when there's a buffer that was shown in the window before.
69 (Bug#9419)
70 (display-buffer-pop-up-frame, display-buffer-pop-up-window): Set
71 window's previous buffers to nil.
72
732011-09-03 Eli Zaretskii <eliz@gnu.org>
74
75 * mail/rmailmm.el (rmail-mime-insert-tagline): Insert an extra
76 newline before and after the tag line, so it doesn't interfere
77 with determining the paragraph direction of bidirectional text.
78
12011-09-03 Leo Liu <sdl.web@gmail.com> 792011-09-03 Leo Liu <sdl.web@gmail.com>
2 80
3 * files.el (find-file-not-true-dirname-list): Remove. (Bug#9422) 81 * files.el (find-file-not-true-dirname-list): Remove. (Bug#9422)
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index db5ee353c3c..9d719136cc1 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,22 @@
12011-09-04 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * gnus.el (gnus-home-directory): Add warning about setting in .gnus.el
4 (bug#9405).
5
6 * gnus-score.el (gnus-summary-increase-score): Doc clarification
7 (bug#9421).
8
9 * gnus-spec.el (gnus-face-0): Make all the face specs into defcustoms
10 (bug#9425).
11
12 * gnus-art.el (gnus-treatment-function-alist): Remove CRs as the first
13 thing (bug#9426).
14
152011-09-03 Lars Magne Ingebrigtsen <larsi@gnus.org>
16
17 * nnimap.el (nnimap-open-connection-1): Use the correct port number in
18 the error message.
19
12011-09-02 Eli Zaretskii <eliz@gnu.org> 202011-09-02 Eli Zaretskii <eliz@gnu.org>
2 21
3 * message.el (message-setup-1): Return t (Bug#9392). 22 * message.el (message-setup-1): Return t (Bug#9392).
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index eaf0ed52f51..9d962fc6d99 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -1657,14 +1657,14 @@ regexp."
1657 1657
1658(defvar gnus-article-mime-handle-alist-1 nil) 1658(defvar gnus-article-mime-handle-alist-1 nil)
1659(defvar gnus-treatment-function-alist 1659(defvar gnus-treatment-function-alist
1660 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig) 1660 '((gnus-treat-strip-cr gnus-article-remove-cr)
1661 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1661 (gnus-treat-strip-banner gnus-article-strip-banner) 1662 (gnus-treat-strip-banner gnus-article-strip-banner)
1662 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body) 1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1663 (gnus-treat-highlight-signature gnus-article-highlight-signature) 1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1664 (gnus-treat-buttonize gnus-article-add-buttons) 1665 (gnus-treat-buttonize gnus-article-add-buttons)
1665 (gnus-treat-fill-article gnus-article-fill-cited-article) 1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1666 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines) 1667 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1667 (gnus-treat-strip-cr gnus-article-remove-cr)
1668 (gnus-treat-unsplit-urls gnus-article-unsplit-urls) 1668 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1669 (gnus-treat-display-x-face gnus-article-display-x-face) 1669 (gnus-treat-display-x-face gnus-article-display-x-face)
1670 (gnus-treat-display-face gnus-article-display-face) 1670 (gnus-treat-display-face gnus-article-display-face)
diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index eb7234a811e..d8e424eacc8 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -522,9 +522,10 @@ of the last successful match.")
522(defun gnus-summary-lower-score (&optional score symp) 522(defun gnus-summary-lower-score (&optional score symp)
523 "Make a score entry based on the current article. 523 "Make a score entry based on the current article.
524The user will be prompted for header to score on, match type, 524The user will be prompted for header to score on, match type,
525permanence, and the string to be used. The numerical prefix will be 525permanence, and the string to be used. The numerical prefix will
526used as score. A symbolic prefix of `a' says to use the `all.SCORE' 526be used as SCORE. A symbolic prefix of `a' (the SYMP parameter)
527file for the command instead of the current score file." 527says to use the `all.SCORE' file for the command instead of the
528current score file."
528 (interactive (gnus-interactive "P\ny")) 529 (interactive (gnus-interactive "P\ny"))
529 (gnus-summary-increase-score (- (gnus-score-delta-default score)) symp)) 530 (gnus-summary-increase-score (- (gnus-score-delta-default score)) symp))
530 531
@@ -537,9 +538,10 @@ file for the command instead of the current score file."
537(defun gnus-summary-increase-score (&optional score symp) 538(defun gnus-summary-increase-score (&optional score symp)
538 "Make a score entry based on the current article. 539 "Make a score entry based on the current article.
539The user will be prompted for header to score on, match type, 540The user will be prompted for header to score on, match type,
540permanence, and the string to be used. The numerical prefix will be 541permanence, and the string to be used. The numerical prefix will
541used as score. A symbolic prefix of `a' says to use the `all.SCORE' 542be used as SCORE. A symbolic prefix of `a' (the SYMP parameter)
542file for the command instead of the current score file." 543says to use the `all.SCORE' file for the command instead of the
544current score file."
543 (interactive (gnus-interactive "P\ny")) 545 (interactive (gnus-interactive "P\ny"))
544 (let* ((nscore (gnus-score-delta-default score)) 546 (let* ((nscore (gnus-score-delta-default score))
545 (prefix (if (< nscore 0) ?L ?I)) 547 (prefix (if (< nscore 0) ?L ?I))
diff --git a/lisp/gnus/gnus-spec.el b/lisp/gnus/gnus-spec.el
index 0fa64a84b75..31cb9864ff2 100644
--- a/lisp/gnus/gnus-spec.el
+++ b/lisp/gnus/gnus-spec.el
@@ -264,11 +264,30 @@ Return a list of updated types."
264 (push (cons 'version emacs-version) gnus-format-specs)) 264 (push (cons 'version emacs-version) gnus-format-specs))
265 updated)) 265 updated))
266 266
267(defvar gnus-mouse-face-0 'highlight) 267(defcustom gnus-mouse-face-0 'highlight
268(defvar gnus-mouse-face-1 'highlight) 268 "The \"%(hello%)\" face."
269(defvar gnus-mouse-face-2 'highlight) 269 :group 'gnus-format
270(defvar gnus-mouse-face-3 'highlight) 270 :type 'face)
271(defvar gnus-mouse-face-4 'highlight) 271
272(defcustom gnus-mouse-face-1 'highlight
273 "The \"%1(hello%)\" face."
274 :group 'gnus-format
275 :type 'face)
276
277(defcustom gnus-mouse-face-2 'highlight
278 "The \"%2(hello%)\" face."
279 :group 'gnus-format
280 :type 'face)
281
282(defcustom gnus-mouse-face-3 'highlight
283 "The \"%3(hello%)\" face."
284 :group 'gnus-format
285 :type 'face)
286
287(defcustom gnus-mouse-face-4 'highlight
288 "The \"%4(hello%)\" face."
289 :group 'gnus-format
290 :type 'face)
272 291
273(defun gnus-mouse-face-function (form type) 292(defun gnus-mouse-face-function (form type)
274 `(gnus-put-text-property 293 `(gnus-put-text-property
@@ -278,11 +297,30 @@ Return a list of updated types."
278 'gnus-mouse-face 297 'gnus-mouse-face
279 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type))))))) 298 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
280 299
281(defvar gnus-face-0 'bold) 300(defcustom gnus-face-0 'bold
282(defvar gnus-face-1 'italic) 301 "The \"%{hello%}\" face."
283(defvar gnus-face-2 'bold-italic) 302 :group 'gnus-format
284(defvar gnus-face-3 'bold) 303 :type 'face)
285(defvar gnus-face-4 'bold) 304
305(defcustom gnus-face-1 'italic
306 "The \"%1{hello%}\" face."
307 :group 'gnus-format
308 :type 'face)
309
310(defcustom gnus-face-2 'bold-italic
311 "The \"%2{hello%}\" face."
312 :group 'gnus-format
313 :type 'face)
314
315(defcustom gnus-face-3 'bold
316 "The \"%3{hello%}\" face."
317 :group 'gnus-format
318 :type 'face)
319
320(defcustom gnus-face-4 'bold
321 "The \"%4{hello%}\" face."
322 :group 'gnus-format
323 :type 'face)
286 324
287(defun gnus-face-face-function (form type) 325(defun gnus-face-face-function (form type)
288 `(gnus-add-text-properties 326 `(gnus-add-text-properties
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index cd9b6eeb949..34759cee06f 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -1245,7 +1245,12 @@ REST is a plist of following:
1245 1245
1246(defcustom gnus-home-directory "~/" 1246(defcustom gnus-home-directory "~/"
1247 "Directory variable that specifies the \"home\" directory. 1247 "Directory variable that specifies the \"home\" directory.
1248All other Gnus file and directory variables are initialized from this variable." 1248All other Gnus file and directory variables are initialized from this variable.
1249
1250Note that Gnus is mostly loaded when the `.gnus.el' file is read.
1251This means that other directory variables that are initialized
1252from this variable won't be set properly if you set this variable
1253in `.gnus.el'. Set this variable in `.emacs' instead."
1249 :group 'gnus-files 1254 :group 'gnus-files
1250 :type 'directory) 1255 :type 'directory)
1251 1256
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index 2dbc465f8c9..52c4b3c4290 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -350,7 +350,6 @@ textual parts.")
350 (with-current-buffer (nnimap-make-process-buffer buffer) 350 (with-current-buffer (nnimap-make-process-buffer buffer)
351 (let* ((coding-system-for-read 'binary) 351 (let* ((coding-system-for-read 'binary)
352 (coding-system-for-write 'binary) 352 (coding-system-for-write 'binary)
353 (port nil)
354 (ports 353 (ports
355 (cond 354 (cond
356 ((memq nnimap-stream '(network plain starttls)) 355 ((memq nnimap-stream '(network plain starttls))
@@ -395,7 +394,7 @@ textual parts.")
395 (if (not stream) 394 (if (not stream)
396 (progn 395 (progn
397 (nnheader-report 'nnimap "Unable to contact %s:%s via %s" 396 (nnheader-report 'nnimap "Unable to contact %s:%s via %s"
398 nnimap-address port nnimap-stream) 397 nnimap-address (car ports) nnimap-stream)
399 'no-connect) 398 'no-connect)
400 (gnus-set-process-query-on-exit-flag stream nil) 399 (gnus-set-process-query-on-exit-flag stream nil)
401 (if (not (gnus-string-match-p "[*.] \\(OK\\|PREAUTH\\)" greeting)) 400 (if (not (gnus-string-match-p "[*.] \\(OK\\|PREAUTH\\)" greeting))
diff --git a/lisp/help.el b/lisp/help.el
index 710dc34ea89..3ed6f79275a 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -132,7 +132,7 @@
132 "What to do to \"exit\" the help buffer. 132 "What to do to \"exit\" the help buffer.
133This is a list 133This is a list
134 (WINDOW . t) delete the selected window (and possibly its frame, 134 (WINDOW . t) delete the selected window (and possibly its frame,
135 see `quit-window' and `View-quit'), go to WINDOW. 135 see `quit-window'), go to WINDOW.
136 (WINDOW . quit-window) do quit-window, then select WINDOW. 136 (WINDOW . quit-window) do quit-window, then select WINDOW.
137 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.") 137 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
138 138
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 252fb112a5d..ac07f07a76b 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -4482,7 +4482,7 @@ With prefix argument N moves forward N messages with these labels.
4482 4482
4483;;;*** 4483;;;***
4484 4484
4485;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "a7d3e7205efa4e20ca9038c9b260ce83") 4485;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "2c8675d7c069c68bc36a4003b15448d1")
4486;;; Generated autoloads from rmailmm.el 4486;;; Generated autoloads from rmailmm.el
4487 4487
4488(autoload 'rmail-mime "rmailmm" "\ 4488(autoload 'rmail-mime "rmailmm" "\
diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el
index 597068562b5..d3351255583 100644
--- a/lisp/mail/rmailmm.el
+++ b/lisp/mail/rmailmm.el
@@ -426,7 +426,7 @@ The value is a vector [ INDEX HEADER TAGLINE BODY END], where
426 "Insert a tag line for MIME-entity ENTITY. 426 "Insert a tag line for MIME-entity ENTITY.
427ITEM-LIST is a list of strings or button-elements (list) to be added 427ITEM-LIST is a list of strings or button-elements (list) to be added
428to the tag line." 428to the tag line."
429 (insert "[") 429 (insert "\n[")
430 (let ((tag (aref (rmail-mime-entity-tagline entity) 0))) 430 (let ((tag (aref (rmail-mime-entity-tagline entity) 0)))
431 (if (> (length tag) 0) (insert (substring tag 1) ":"))) 431 (if (> (length tag) 0) (insert (substring tag 1) ":")))
432 (insert (car (rmail-mime-entity-type entity)) " ") 432 (insert (car (rmail-mime-entity-type entity)) " ")
@@ -439,7 +439,7 @@ to the tag line."
439 (if (stringp item) 439 (if (stringp item)
440 (insert item) 440 (insert item)
441 (apply 'insert-button item)))) 441 (apply 'insert-button item))))
442 (insert "]\n")) 442 (insert "]\n\n"))
443 443
444(defun rmail-mime-update-tagline (entity) 444(defun rmail-mime-update-tagline (entity)
445 "Update the current tag line for MIME-entity ENTITY." 445 "Update the current tag line for MIME-entity ENTITY."
diff --git a/lisp/mail/sendmail.el b/lisp/mail/sendmail.el
index 158435de86b..cb02a4b374d 100644
--- a/lisp/mail/sendmail.el
+++ b/lisp/mail/sendmail.el
@@ -156,51 +156,6 @@ This is used by the default mail-sending commands. See also
156 :version "24.1" 156 :version "24.1"
157 :group 'sendmail) 157 :group 'sendmail)
158 158
159(defvar sendmail-query-once-function 'query
160 "Either a function to send email, or the symbol `query'.")
161
162;;;###autoload
163(defun sendmail-query-once ()
164 "Send an email via `sendmail-query-once-function'.
165If `sendmail-query-once-function' is `query', ask the user what
166function to use, and then save that choice."
167 (when (equal sendmail-query-once-function 'query)
168 (let* ((mail-buffer (current-buffer))
169 (default
170 (cond
171 ((or (and window-system (eq system-type 'darwin))
172 (eq system-type 'windows-nt))
173 'mailclient-send-it)
174 ((and sendmail-program
175 (executable-find sendmail-program))
176 'sendmail-send-it)))
177 (function
178 (if (or (not default)
179 ;; We have detected no OS-level mail senders, or we
180 ;; have already configured smtpmail, so we use the
181 ;; internal SMTP service.
182 (and (boundp 'smtpmail-smtp-server)
183 smtpmail-smtp-server))
184 'smtpmail-send-it
185 ;; Query the user.
186 (unwind-protect
187 (progn
188 (pop-to-buffer "*Mail Help*")
189 (erase-buffer)
190 (insert "Sending mail from Emacs hasn't been set up yet.\n\n"
191 "Type `y' to configure outgoing SMTP, or `n' to use\n"
192 "the default mail sender on your system.\n\n"
193 "To change this again at a later date, customize the\n"
194 "`send-mail-function' variable.\n")
195 (goto-char (point-min))
196 (if (y-or-n-p "Configure outgoing SMTP in Emacs? ")
197 'smtpmail-send-it
198 default))
199 (kill-buffer (current-buffer))
200 (set-buffer mail-buffer)))))
201 (customize-save-variable 'sendmail-query-once-function function)))
202 (funcall sendmail-query-once-function))
203
204;;;###autoload 159;;;###autoload
205(defcustom mail-header-separator (purecopy "--text follows this line--") 160(defcustom mail-header-separator (purecopy "--text follows this line--")
206 "Line used to separate headers from text in messages being composed." 161 "Line used to separate headers from text in messages being composed."
@@ -543,6 +498,51 @@ by Emacs.)")
543 "Additional expressions to highlight in Mail mode.") 498 "Additional expressions to highlight in Mail mode.")
544 499
545 500
501;;;###autoload
502(defun sendmail-query-once ()
503 "Query for `send-mail-function' and send mail with it.
504This also saves the value of `send-mail-function' via Customize."
505 (let* ((mail-buffer (current-buffer))
506 ;; Compute default mail sender, preferring smtpmail if it's
507 ;; already configured.
508 (default (cond
509 ((and (boundp 'smtpmail-smtp-server)
510 smtpmail-smtp-server)
511 'smtpmail-send-it)
512 ((or (and window-system (eq system-type 'darwin))
513 (eq system-type 'windows-nt))
514 'mailclient-send-it)
515 ((and sendmail-program
516 (executable-find sendmail-program))
517 'sendmail-send-it)))
518 (send-function (if (eq default 'smtpmail-send-it)
519 'smtpmail-send-it)))
520 (unless send-function
521 ;; Query the user.
522 (with-temp-buffer
523 (rename-buffer "*Mail Help*" t)
524 (erase-buffer)
525 (insert "Emacs has not been set up for sending mail.\n
526Type `y' to configure and use Emacs as a mail client,
527or `n' to use your system's default mailer.\n
528To change your decision later, customize `send-mail-function'.\n")
529 (goto-char (point-min))
530 (display-buffer (current-buffer))
531 (if (y-or-n-p "Set up Emacs for sending SMTP mail? ")
532 ;; FIXME: We should check and correct the From: field too.
533 (setq send-function 'smtpmail-send-it)
534 (setq send-function default))))
535 (when send-function
536 (customize-save-variable 'send-mail-function send-function)
537 ;; HACK: Message mode stupidly has `message-send-mail-function',
538 ;; so we must update it too or sending again in the current
539 ;; Emacs session will still call `sendmail-query-once'.
540 (and (boundp 'message-send-mail-function)
541 (eq message-send-mail-function 'sendmail-query-once)
542 (customize-set-variable 'message-send-mail-function
543 send-function))
544 (funcall send-function))))
545
546(defun sendmail-sync-aliases () 546(defun sendmail-sync-aliases ()
547 (when mail-personal-alias-file 547 (when mail-personal-alias-file
548 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file)))) 548 (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index 69c49c471c0..544570a1bc3 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -490,7 +490,7 @@ The list is in preference order.")
490 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions))) 490 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions)))
491 (mech (car (smtpmail-intersection mechs smtpmail-auth-supported))) 491 (mech (car (smtpmail-intersection mechs smtpmail-auth-supported)))
492 (auth-source-creation-prompts 492 (auth-source-creation-prompts
493 '((user . "SMTP user at %h: ") 493 '((user . "SMTP user name for %h: ")
494 (secret . "SMTP password for %u@%h: "))) 494 (secret . "SMTP password for %u@%h: ")))
495 (auth-info (car 495 (auth-info (car
496 (auth-source-search 496 (auth-source-search
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 71b3fe0c4a1..06bbfb0b78c 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -1556,18 +1556,16 @@ record activity."
1556 1556
1557 ;; keep window on bottom line if it was already there 1557 ;; keep window on bottom line if it was already there
1558 (when rcirc-scroll-show-maximum-output 1558 (when rcirc-scroll-show-maximum-output
1559 (walk-windows (lambda (w) 1559 (let ((window (get-buffer-window)))
1560 (when (eq (window-buffer w) (current-buffer)) 1560 (when window
1561 (with-current-buffer (window-buffer w) 1561 (with-selected-window window
1562 (when (eq major-mode 'rcirc-mode) 1562 (when (eq major-mode 'rcirc-mode)
1563 (with-selected-window w 1563 (when (<= (- (window-height)
1564 (when (<= (- (window-height) 1564 (count-screen-lines (window-point)
1565 (count-screen-lines (window-point) 1565 (window-start))
1566 (window-start)) 1566 1)
1567 1) 1567 0)
1568 0) 1568 (recenter -1)))))))
1569 (recenter -1)))))))
1570 nil t))
1571 1569
1572 ;; flush undo (can we do something smarter here?) 1570 ;; flush undo (can we do something smarter here?)
1573 (buffer-disable-undo) 1571 (buffer-disable-undo)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 428bd6422d8..1fa358e9277 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -28,7 +28,6 @@
28 28
29(eval-when-compile (require 'cl)) ; ignore-errors 29(eval-when-compile (require 'cl)) ; ignore-errors
30(require 'tramp) 30(require 'tramp)
31(require 'shell)
32 31
33;; Pacify byte-compiler. The function is needed on XEmacs only. I'm 32;; Pacify byte-compiler. The function is needed on XEmacs only. I'm
34;; not sure at all that this is the right way to do it, but let's hope 33;; not sure at all that this is the right way to do it, but let's hope
@@ -91,7 +90,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
91 '("rcp" 90 '("rcp"
92 (tramp-login-program "rsh") 91 (tramp-login-program "rsh")
93 (tramp-login-args (("%h") ("-l" "%u"))) 92 (tramp-login-args (("%h") ("-l" "%u")))
94 (tramp-remote-sh "/bin/sh") 93 (tramp-remote-shell "/bin/sh")
94 (tramp-remote-shell-args ("-c"))
95 (tramp-copy-program "rcp") 95 (tramp-copy-program "rcp")
96 (tramp-copy-args (("-p" "%k") ("-r"))) 96 (tramp-copy-args (("-p" "%k") ("-r")))
97 (tramp-copy-keep-date t) 97 (tramp-copy-keep-date t)
@@ -101,7 +101,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
101 '("remcp" 101 '("remcp"
102 (tramp-login-program "remsh") 102 (tramp-login-program "remsh")
103 (tramp-login-args (("%h") ("-l" "%u"))) 103 (tramp-login-args (("%h") ("-l" "%u")))
104 (tramp-remote-sh "/bin/sh") 104 (tramp-remote-shell "/bin/sh")
105 (tramp-remote-shell-args ("-c"))
105 (tramp-copy-program "rcp") 106 (tramp-copy-program "rcp")
106 (tramp-copy-args (("-p" "%k"))) 107 (tramp-copy-args (("-p" "%k")))
107 (tramp-copy-keep-date t))) 108 (tramp-copy-keep-date t)))
@@ -111,7 +112,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
111 (tramp-login-program "ssh") 112 (tramp-login-program "ssh")
112 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h"))) 113 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h")))
113 (tramp-async-args (("-q"))) 114 (tramp-async-args (("-q")))
114 (tramp-remote-sh "/bin/sh") 115 (tramp-remote-shell "/bin/sh")
116 (tramp-remote-shell-args ("-c"))
115 (tramp-copy-program "scp") 117 (tramp-copy-program "scp")
116 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r"))) 118 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r")))
117 (tramp-copy-keep-date t) 119 (tramp-copy-keep-date t)
@@ -127,7 +129,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
127 (tramp-login-args (("-l" "%u") ("-p" "%p") 129 (tramp-login-args (("-l" "%u") ("-p" "%p")
128 ("-1") ("-e" "none") ("%h"))) 130 ("-1") ("-e" "none") ("%h")))
129 (tramp-async-args (("-q"))) 131 (tramp-async-args (("-q")))
130 (tramp-remote-sh "/bin/sh") 132 (tramp-remote-shell "/bin/sh")
133 (tramp-remote-shell-args ("-c"))
131 (tramp-copy-program "scp") 134 (tramp-copy-program "scp")
132 (tramp-copy-args (("-1") ("-P" "%p") ("-p" "%k") ("-q") ("-r"))) 135 (tramp-copy-args (("-1") ("-P" "%p") ("-p" "%k") ("-q") ("-r")))
133 (tramp-copy-keep-date t) 136 (tramp-copy-keep-date t)
@@ -143,7 +146,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
143 (tramp-login-args (("-l" "%u") ("-p" "%p") 146 (tramp-login-args (("-l" "%u") ("-p" "%p")
144 ("-2") ("-e" "none") ("%h"))) 147 ("-2") ("-e" "none") ("%h")))
145 (tramp-async-args (("-q"))) 148 (tramp-async-args (("-q")))
146 (tramp-remote-sh "/bin/sh") 149 (tramp-remote-shell "/bin/sh")
150 (tramp-remote-shell-args ("-c"))
147 (tramp-copy-program "scp") 151 (tramp-copy-program "scp")
148 (tramp-copy-args (("-2") ("-P" "%p") ("-p" "%k") ("-q") ("-r"))) 152 (tramp-copy-args (("-2") ("-P" "%p") ("-p" "%k") ("-q") ("-r")))
149 (tramp-copy-keep-date t) 153 (tramp-copy-keep-date t)
@@ -161,7 +165,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
161 ("-o" "ControlMaster=yes") 165 ("-o" "ControlMaster=yes")
162 ("-e" "none") ("%h"))) 166 ("-e" "none") ("%h")))
163 (tramp-async-args (("-q"))) 167 (tramp-async-args (("-q")))
164 (tramp-remote-sh "/bin/sh") 168 (tramp-remote-shell "/bin/sh")
169 (tramp-remote-shell-args ("-c"))
165 (tramp-copy-program "scp") 170 (tramp-copy-program "scp")
166 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") 171 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r")
167 ("-o" "ControlPath=%t.%%r@%%h:%%p") 172 ("-o" "ControlPath=%t.%%r@%%h:%%p")
@@ -180,7 +185,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
180 ("-e" "none") ("-t" "-t") 185 ("-e" "none") ("-t" "-t")
181 ("%h") ("/bin/sh"))) 186 ("%h") ("/bin/sh")))
182 (tramp-async-args (("-q"))) 187 (tramp-async-args (("-q")))
183 (tramp-remote-sh "/bin/sh") 188 (tramp-remote-shell "/bin/sh")
189 (tramp-remote-shell-args ("-c"))
184 (tramp-copy-program "scp") 190 (tramp-copy-program "scp")
185 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r"))) 191 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r")))
186 (tramp-copy-keep-date t) 192 (tramp-copy-keep-date t)
@@ -195,7 +201,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
195 (tramp-login-program "ssh") 201 (tramp-login-program "ssh")
196 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h"))) 202 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h")))
197 (tramp-async-args (("-q"))) 203 (tramp-async-args (("-q")))
198 (tramp-remote-sh "/bin/sh") 204 (tramp-remote-shell "/bin/sh")
205 (tramp-remote-shell-args ("-c"))
199 (tramp-copy-program "sftp"))) 206 (tramp-copy-program "sftp")))
200;;;###tramp-autoload 207;;;###tramp-autoload
201(add-to-list 'tramp-methods 208(add-to-list 'tramp-methods
@@ -203,7 +210,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
203 (tramp-login-program "ssh") 210 (tramp-login-program "ssh")
204 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h"))) 211 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h")))
205 (tramp-async-args (("-q"))) 212 (tramp-async-args (("-q")))
206 (tramp-remote-sh "/bin/sh") 213 (tramp-remote-shell "/bin/sh")
214 (tramp-remote-shell-args ("-c"))
207 (tramp-copy-program "rsync") 215 (tramp-copy-program "rsync")
208 (tramp-copy-args (("-e" "ssh") ("-t" "%k") ("-r"))) 216 (tramp-copy-args (("-e" "ssh") ("-t" "%k") ("-r")))
209 (tramp-copy-keep-date t) 217 (tramp-copy-keep-date t)
@@ -218,7 +226,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
218 ("-o" "ControlMaster=yes") 226 ("-o" "ControlMaster=yes")
219 ("-e" "none") ("%h"))) 227 ("-e" "none") ("%h")))
220 (tramp-async-args (("-q"))) 228 (tramp-async-args (("-q")))
221 (tramp-remote-sh "/bin/sh") 229 (tramp-remote-shell "/bin/sh")
230 (tramp-remote-shell-args ("-c"))
222 (tramp-copy-program "rsync") 231 (tramp-copy-program "rsync")
223 (tramp-copy-args (("-t" "%k") ("-r"))) 232 (tramp-copy-args (("-t" "%k") ("-r")))
224 (tramp-copy-env (("RSYNC_RSH") 233 (tramp-copy-env (("RSYNC_RSH")
@@ -234,20 +243,23 @@ detected as prompt when being sent on echoing hosts, therefore.")
234 '("rsh" 243 '("rsh"
235 (tramp-login-program "rsh") 244 (tramp-login-program "rsh")
236 (tramp-login-args (("%h") ("-l" "%u"))) 245 (tramp-login-args (("%h") ("-l" "%u")))
237 (tramp-remote-sh "/bin/sh"))) 246 (tramp-remote-shell "/bin/sh")
247 (tramp-remote-shell-args ("-c"))))
238;;;###tramp-autoload 248;;;###tramp-autoload
239(add-to-list 'tramp-methods 249(add-to-list 'tramp-methods
240 '("remsh" 250 '("remsh"
241 (tramp-login-program "remsh") 251 (tramp-login-program "remsh")
242 (tramp-login-args (("%h") ("-l" "%u"))) 252 (tramp-login-args (("%h") ("-l" "%u")))
243 (tramp-remote-sh "/bin/sh"))) 253 (tramp-remote-shell "/bin/sh")
254 (tramp-remote-shell-args ("-c"))))
244;;;###tramp-autoload 255;;;###tramp-autoload
245(add-to-list 'tramp-methods 256(add-to-list 'tramp-methods
246 '("ssh" 257 '("ssh"
247 (tramp-login-program "ssh") 258 (tramp-login-program "ssh")
248 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h"))) 259 (tramp-login-args (("-l" "%u") ("-p" "%p") ("-e" "none") ("%h")))
249 (tramp-async-args (("-q"))) 260 (tramp-async-args (("-q")))
250 (tramp-remote-sh "/bin/sh") 261 (tramp-remote-shell "/bin/sh")
262 (tramp-remote-shell-args ("-c"))
251 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null") 263 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
252 ("-o" "UserKnownHostsFile=/dev/null") 264 ("-o" "UserKnownHostsFile=/dev/null")
253 ("-o" "StrictHostKeyChecking=no"))) 265 ("-o" "StrictHostKeyChecking=no")))
@@ -259,7 +271,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
259 (tramp-login-args (("-l" "%u") ("-p" "%p") 271 (tramp-login-args (("-l" "%u") ("-p" "%p")
260 ("-1") ("-e" "none") ("%h"))) 272 ("-1") ("-e" "none") ("%h")))
261 (tramp-async-args (("-q"))) 273 (tramp-async-args (("-q")))
262 (tramp-remote-sh "/bin/sh") 274 (tramp-remote-shell "/bin/sh")
275 (tramp-remote-shell-args ("-c"))
263 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null") 276 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
264 ("-o" "UserKnownHostsFile=/dev/null") 277 ("-o" "UserKnownHostsFile=/dev/null")
265 ("-o" "StrictHostKeyChecking=no"))) 278 ("-o" "StrictHostKeyChecking=no")))
@@ -271,7 +284,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
271 (tramp-login-args (("-l" "%u") ("-p" "%p") 284 (tramp-login-args (("-l" "%u") ("-p" "%p")
272 ("-2") ("-e" "none") ("%h"))) 285 ("-2") ("-e" "none") ("%h")))
273 (tramp-async-args (("-q"))) 286 (tramp-async-args (("-q")))
274 (tramp-remote-sh "/bin/sh") 287 (tramp-remote-shell "/bin/sh")
288 (tramp-remote-shell-args ("-c"))
275 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null") 289 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
276 ("-o" "UserKnownHostsFile=/dev/null") 290 ("-o" "UserKnownHostsFile=/dev/null")
277 ("-o" "StrictHostKeyChecking=no"))) 291 ("-o" "StrictHostKeyChecking=no")))
@@ -284,7 +298,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
284 ("-e" "none") ("-t" "-t") 298 ("-e" "none") ("-t" "-t")
285 ("%h") ("/bin/sh"))) 299 ("%h") ("/bin/sh")))
286 (tramp-async-args (("-q"))) 300 (tramp-async-args (("-q")))
287 (tramp-remote-sh "/bin/sh") 301 (tramp-remote-shell "/bin/sh")
302 (tramp-remote-shell-args ("-c"))
288 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null") 303 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
289 ("-o" "UserKnownHostsFile=/dev/null") 304 ("-o" "UserKnownHostsFile=/dev/null")
290 ("-o" "StrictHostKeyChecking=no"))) 305 ("-o" "StrictHostKeyChecking=no")))
@@ -294,38 +309,44 @@ detected as prompt when being sent on echoing hosts, therefore.")
294 '("telnet" 309 '("telnet"
295 (tramp-login-program "telnet") 310 (tramp-login-program "telnet")
296 (tramp-login-args (("%h") ("%p"))) 311 (tramp-login-args (("%h") ("%p")))
297 (tramp-remote-sh "/bin/sh") 312 (tramp-remote-shell "/bin/sh")
313 (tramp-remote-shell-args ("-c"))
298 (tramp-default-port 23))) 314 (tramp-default-port 23)))
299;;;###tramp-autoload 315;;;###tramp-autoload
300(add-to-list 'tramp-methods 316(add-to-list 'tramp-methods
301 '("su" 317 '("su"
302 (tramp-login-program "su") 318 (tramp-login-program "su")
303 (tramp-login-args (("-") ("%u"))) 319 (tramp-login-args (("-") ("%u")))
304 (tramp-remote-sh "/bin/sh"))) 320 (tramp-remote-shell "/bin/sh")
321 (tramp-remote-shell-args ("-c"))))
305;;;###tramp-autoload 322;;;###tramp-autoload
306(add-to-list 'tramp-methods 323(add-to-list 'tramp-methods
307 '("sudo" 324 '("sudo"
308 (tramp-login-program "sudo") 325 (tramp-login-program "sudo")
309 (tramp-login-args (("-u" "%u") ("-s") ("-H") ("-p" "Password:"))) 326 (tramp-login-args (("-u" "%u") ("-s") ("-H") ("-p" "Password:")))
310 (tramp-remote-sh "/bin/sh"))) 327 (tramp-remote-shell "/bin/sh")
328 (tramp-remote-shell-args ("-c"))))
311;;;###tramp-autoload 329;;;###tramp-autoload
312(add-to-list 'tramp-methods 330(add-to-list 'tramp-methods
313 '("ksu" 331 '("ksu"
314 (tramp-login-program "ksu") 332 (tramp-login-program "ksu")
315 (tramp-login-args (("%u") ("-q"))) 333 (tramp-login-args (("%u") ("-q")))
316 (tramp-remote-sh "/bin/sh"))) 334 (tramp-remote-shell "/bin/sh")
335 (tramp-remote-shell-args ("-c"))))
317;;;###tramp-autoload 336;;;###tramp-autoload
318(add-to-list 'tramp-methods 337(add-to-list 'tramp-methods
319 '("krlogin" 338 '("krlogin"
320 (tramp-login-program "krlogin") 339 (tramp-login-program "krlogin")
321 (tramp-login-args (("%h") ("-l" "%u") ("-x"))) 340 (tramp-login-args (("%h") ("-l" "%u") ("-x")))
322 (tramp-remote-sh "/bin/sh"))) 341 (tramp-remote-shell "/bin/sh")
342 (tramp-remote-shell-args ("-c"))))
323;;;###tramp-autoload 343;;;###tramp-autoload
324(add-to-list 'tramp-methods 344(add-to-list 'tramp-methods
325 '("plink" 345 '("plink"
326 (tramp-login-program "plink") 346 (tramp-login-program "plink")
327 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h"))) 347 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h")))
328 (tramp-remote-sh "/bin/sh") 348 (tramp-remote-shell "/bin/sh")
349 (tramp-remote-shell-args ("-c"))
329 (tramp-password-end-of-line "xy") ;see docstring for "xy" 350 (tramp-password-end-of-line "xy") ;see docstring for "xy"
330 (tramp-default-port 22))) 351 (tramp-default-port 22)))
331;;;###tramp-autoload 352;;;###tramp-autoload
@@ -333,7 +354,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
333 '("plink1" 354 '("plink1"
334 (tramp-login-program "plink") 355 (tramp-login-program "plink")
335 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-1" "-ssh") ("%h"))) 356 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-1" "-ssh") ("%h")))
336 (tramp-remote-sh "/bin/sh") 357 (tramp-remote-shell "/bin/sh")
358 (tramp-remote-shell-args ("-c"))
337 (tramp-password-end-of-line "xy") ;see docstring for "xy" 359 (tramp-password-end-of-line "xy") ;see docstring for "xy"
338 (tramp-default-port 22))) 360 (tramp-default-port 22)))
339;;;###tramp-autoload 361;;;###tramp-autoload
@@ -348,13 +370,15 @@ detected as prompt when being sent on echoing hosts, therefore.")
348 tramp-terminal-type 370 tramp-terminal-type
349 tramp-initial-end-of-output)) 371 tramp-initial-end-of-output))
350 ("/bin/sh"))) 372 ("/bin/sh")))
351 (tramp-remote-sh "/bin/sh"))) 373 (tramp-remote-shell "/bin/sh")
374 (tramp-remote-shell-args ("-c"))))
352;;;###tramp-autoload 375;;;###tramp-autoload
353(add-to-list 'tramp-methods 376(add-to-list 'tramp-methods
354 '("pscp" 377 '("pscp"
355 (tramp-login-program "plink") 378 (tramp-login-program "plink")
356 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h"))) 379 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h")))
357 (tramp-remote-sh "/bin/sh") 380 (tramp-remote-shell "/bin/sh")
381 (tramp-remote-shell-args ("-c"))
358 (tramp-copy-program "pscp") 382 (tramp-copy-program "pscp")
359 (tramp-copy-args (("-P" "%p") ("-scp") ("-p" "%k") 383 (tramp-copy-args (("-P" "%p") ("-scp") ("-p" "%k")
360 ("-q") ("-r"))) 384 ("-q") ("-r")))
@@ -367,7 +391,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
367 '("psftp" 391 '("psftp"
368 (tramp-login-program "plink") 392 (tramp-login-program "plink")
369 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h"))) 393 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%h")))
370 (tramp-remote-sh "/bin/sh") 394 (tramp-remote-shell "/bin/sh")
395 (tramp-remote-shell-args ("-c"))
371 (tramp-copy-program "pscp") 396 (tramp-copy-program "pscp")
372 (tramp-copy-args (("-P" "%p") ("-sftp") ("-p" "%k") 397 (tramp-copy-args (("-P" "%p") ("-sftp") ("-p" "%k")
373 ("-q") ("-r"))) 398 ("-q") ("-r")))
@@ -379,7 +404,8 @@ detected as prompt when being sent on echoing hosts, therefore.")
379 '("fcp" 404 '("fcp"
380 (tramp-login-program "fsh") 405 (tramp-login-program "fsh")
381 (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i"))) 406 (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i")))
382 (tramp-remote-sh "/bin/sh -i") 407 (tramp-remote-shell "/bin/sh")
408 (tramp-remote-shell-args ("-i") ("-c"))
383 (tramp-copy-program "fcp") 409 (tramp-copy-program "fcp")
384 (tramp-copy-args (("-p" "%k"))) 410 (tramp-copy-args (("-p" "%k")))
385 (tramp-copy-keep-date t))) 411 (tramp-copy-keep-date t)))
@@ -942,7 +968,7 @@ This is used to map a mode number to a permission string.")
942 (executable-find . tramp-sh-handle-executable-find) 968 (executable-find . tramp-sh-handle-executable-find)
943 (start-file-process . tramp-sh-handle-start-file-process) 969 (start-file-process . tramp-sh-handle-start-file-process)
944 (process-file . tramp-sh-handle-process-file) 970 (process-file . tramp-sh-handle-process-file)
945 (shell-command . tramp-sh-handle-shell-command) 971 (shell-command . tramp-handle-shell-command)
946 (insert-directory . tramp-sh-handle-insert-directory) 972 (insert-directory . tramp-sh-handle-insert-directory)
947 (expand-file-name . tramp-sh-handle-expand-file-name) 973 (expand-file-name . tramp-sh-handle-expand-file-name)
948 (substitute-in-file-name . tramp-handle-substitute-in-file-name) 974 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
@@ -2853,7 +2879,7 @@ the result will be a local, non-Tramp, filename."
2853 ;; `process-file-side-effects' has been introduced with GNU 2879 ;; `process-file-side-effects' has been introduced with GNU
2854 ;; Emacs 23.2. If set to `nil', no remote file will be changed 2880 ;; Emacs 23.2. If set to `nil', no remote file will be changed
2855 ;; by `program'. If it doesn't exist, we assume its default 2881 ;; by `program'. If it doesn't exist, we assume its default
2856 ;; value 't'. 2882 ;; value `t'.
2857 (unless (and (boundp 'process-file-side-effects) 2883 (unless (and (boundp 'process-file-side-effects)
2858 (not (symbol-value 'process-file-side-effects))) 2884 (not (symbol-value 'process-file-side-effects)))
2859 (tramp-flush-directory-property v "")) 2885 (tramp-flush-directory-property v ""))
@@ -2873,87 +2899,6 @@ the result will be a local, non-Tramp, filename."
2873 (apply 'call-process program tmpfile buffer display args) 2899 (apply 'call-process program tmpfile buffer display args)
2874 (delete-file tmpfile)))) 2900 (delete-file tmpfile))))
2875 2901
2876(defun tramp-sh-handle-shell-command
2877 (command &optional output-buffer error-buffer)
2878 "Like `shell-command' for Tramp files."
2879 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
2880 ;; We cannot use `shell-file-name' and `shell-command-switch',
2881 ;; they are variables of the local host.
2882 (args (list
2883 (tramp-get-method-parameter
2884 (tramp-file-name-method
2885 (tramp-dissect-file-name default-directory))
2886 'tramp-remote-sh)
2887 "-c" (substring command 0 asynchronous)))
2888 current-buffer-p
2889 (output-buffer
2890 (cond
2891 ((bufferp output-buffer) output-buffer)
2892 ((stringp output-buffer) (get-buffer-create output-buffer))
2893 (output-buffer
2894 (setq current-buffer-p t)
2895 (current-buffer))
2896 (t (get-buffer-create
2897 (if asynchronous
2898 "*Async Shell Command*"
2899 "*Shell Command Output*")))))
2900 (error-buffer
2901 (cond
2902 ((bufferp error-buffer) error-buffer)
2903 ((stringp error-buffer) (get-buffer-create error-buffer))))
2904 (buffer
2905 (if (and (not asynchronous) error-buffer)
2906 (with-parsed-tramp-file-name default-directory nil
2907 (list output-buffer (tramp-make-tramp-temp-file v)))
2908 output-buffer))
2909 (p (get-buffer-process output-buffer)))
2910
2911 ;; Check whether there is another process running. Tramp does not
2912 ;; support 2 (asynchronous) processes in parallel.
2913 (when p
2914 (if (yes-or-no-p "A command is running. Kill it? ")
2915 (ignore-errors (kill-process p))
2916 (error "Shell command in progress")))
2917
2918 (if current-buffer-p
2919 (progn
2920 (barf-if-buffer-read-only)
2921 (push-mark nil t))
2922 (with-current-buffer output-buffer
2923 (setq buffer-read-only nil)
2924 (erase-buffer)))
2925
2926 (if (and (not current-buffer-p) (integerp asynchronous))
2927 (prog1
2928 ;; Run the process.
2929 (apply 'start-file-process "*Async Shell*" buffer args)
2930 ;; Display output.
2931 (pop-to-buffer output-buffer)
2932 (setq mode-line-process '(":%s"))
2933 (shell-mode))
2934
2935 (prog1
2936 ;; Run the process.
2937 (apply 'process-file (car args) nil buffer nil (cdr args))
2938 ;; Insert error messages if they were separated.
2939 (when (listp buffer)
2940 (with-current-buffer error-buffer
2941 (insert-file-contents (cadr buffer)))
2942 (delete-file (cadr buffer)))
2943 (if current-buffer-p
2944 ;; This is like exchange-point-and-mark, but doesn't
2945 ;; activate the mark. It is cleaner to avoid activation,
2946 ;; even though the command loop would deactivate the mark
2947 ;; because we inserted text.
2948 (goto-char (prog1 (mark t)
2949 (set-marker (mark-marker) (point)
2950 (current-buffer))))
2951 ;; There's some output, display it.
2952 (when (with-current-buffer output-buffer (> (point-max) (point-min)))
2953 (if (functionp 'display-message-or-buffer)
2954 (tramp-compat-funcall 'display-message-or-buffer output-buffer)
2955 (pop-to-buffer output-buffer))))))))
2956
2957(defun tramp-sh-handle-file-local-copy (filename) 2902(defun tramp-sh-handle-file-local-copy (filename)
2958 "Like `file-local-copy' for Tramp files." 2903 "Like `file-local-copy' for Tramp files."
2959 (with-parsed-tramp-file-name filename nil 2904 (with-parsed-tramp-file-name filename nil
@@ -3680,7 +3625,7 @@ file exists and nonzero exit status otherwise."
3680 (tramp-set-connection-property 3625 (tramp-set-connection-property
3681 vec "remote-shell" 3626 vec "remote-shell"
3682 (tramp-get-method-parameter 3627 (tramp-get-method-parameter
3683 (tramp-file-name-method vec) 'tramp-remote-sh))))))))) 3628 (tramp-file-name-method vec) 'tramp-remote-shell)))))))))
3684 3629
3685;; Utility functions. 3630;; Utility functions.
3686 3631
@@ -3716,7 +3661,8 @@ process to set up. VEC specifies the connection."
3716 ;; discarded as well. 3661 ;; discarded as well.
3717 (tramp-open-shell 3662 (tramp-open-shell
3718 vec 3663 vec
3719 (tramp-get-method-parameter (tramp-file-name-method vec) 'tramp-remote-sh)) 3664 (tramp-get-method-parameter
3665 (tramp-file-name-method vec) 'tramp-remote-shell))
3720 3666
3721 ;; Disable echo. 3667 ;; Disable echo.
3722 (tramp-message vec 5 "Setting up remote shell environment") 3668 (tramp-message vec 5 "Setting up remote shell environment")
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 274bc72391b..6475ea42ec8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -58,6 +58,7 @@
58;;; Code: 58;;; Code:
59 59
60(require 'tramp-compat) 60(require 'tramp-compat)
61(require 'shell)
61 62
62;;; User Customizable Internal Variables: 63;;; User Customizable Internal Variables:
63 64
@@ -190,13 +191,16 @@ See the variable `tramp-encoding-shell' for more information."
190This is a list of entries of the form (NAME PARAM1 PARAM2 ...). 191This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
191Each NAME stands for a remote access method. Each PARAM is a 192Each NAME stands for a remote access method. Each PARAM is a
192pair of the form (KEY VALUE). The following KEYs are defined: 193pair of the form (KEY VALUE). The following KEYs are defined:
193 * `tramp-remote-sh' 194 * `tramp-remote-shell'
194 This specifies the Bourne shell to use on the remote host. This 195 This specifies the Bourne shell to use on the remote host. This
195 MUST be a Bourne-like shell. It is normally not necessary to set 196 MUST be a Bourne-like shell. It is normally not necessary to set
196 this to any value other than \"/bin/sh\": Tramp wants to use a shell 197 this to any value other than \"/bin/sh\": Tramp wants to use a shell
197 which groks tilde expansion, but it can search for it. Also note 198 which groks tilde expansion, but it can search for it. Also note
198 that \"/bin/sh\" exists on all Unixen, this might not be true for 199 that \"/bin/sh\" exists on all Unixen, this might not be true for
199 the value that you decide to use. You Have Been Warned. 200 the value that you decide to use. You Have Been Warned.
201 * `tramp-remote-shell-args'
202 For implementation of `shell-command', this specifies the
203 argument to let `tramp-remote-shell' run a command.
200 * `tramp-login-program' 204 * `tramp-login-program'
201 This specifies the name of the program to use for logging in to the 205 This specifies the name of the program to use for logging in to the
202 remote host. This may be the name of rsh or a workalike program, 206 remote host. This may be the name of rsh or a workalike program,
@@ -2959,6 +2963,92 @@ User is always nil."
2959 (delete-file local-copy))))) 2963 (delete-file local-copy)))))
2960 t))) 2964 t)))
2961 2965
2966(defun tramp-handle-shell-command
2967 (command &optional output-buffer error-buffer)
2968 "Like `shell-command' for Tramp files."
2969 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
2970 ;; We cannot use `shell-file-name' and `shell-command-switch',
2971 ;; they are variables of the local host.
2972 (args (append
2973 (cons
2974 (tramp-get-method-parameter
2975 (tramp-file-name-method
2976 (tramp-dissect-file-name default-directory))
2977 'tramp-remote-shell)
2978 (tramp-get-method-parameter
2979 (tramp-file-name-method
2980 (tramp-dissect-file-name default-directory))
2981 'tramp-remote-shell-args))
2982 (list (substring command 0 asynchronous))))
2983 current-buffer-p
2984 (output-buffer
2985 (cond
2986 ((bufferp output-buffer) output-buffer)
2987 ((stringp output-buffer) (get-buffer-create output-buffer))
2988 (output-buffer
2989 (setq current-buffer-p t)
2990 (current-buffer))
2991 (t (get-buffer-create
2992 (if asynchronous
2993 "*Async Shell Command*"
2994 "*Shell Command Output*")))))
2995 (error-buffer
2996 (cond
2997 ((bufferp error-buffer) error-buffer)
2998 ((stringp error-buffer) (get-buffer-create error-buffer))))
2999 (buffer
3000 (if (and (not asynchronous) error-buffer)
3001 (with-parsed-tramp-file-name default-directory nil
3002 (list output-buffer (tramp-make-tramp-temp-file v)))
3003 output-buffer))
3004 (p (get-buffer-process output-buffer)))
3005
3006 ;; Check whether there is another process running. Tramp does not
3007 ;; support 2 (asynchronous) processes in parallel.
3008 (when p
3009 (if (yes-or-no-p "A command is running. Kill it? ")
3010 (ignore-errors (kill-process p))
3011 (error "Shell command in progress")))
3012
3013 (if current-buffer-p
3014 (progn
3015 (barf-if-buffer-read-only)
3016 (push-mark nil t))
3017 (with-current-buffer output-buffer
3018 (setq buffer-read-only nil)
3019 (erase-buffer)))
3020
3021 (if (and (not current-buffer-p) (integerp asynchronous))
3022 (prog1
3023 ;; Run the process.
3024 (apply 'start-file-process "*Async Shell*" buffer args)
3025 ;; Display output.
3026 (pop-to-buffer output-buffer)
3027 (setq mode-line-process '(":%s"))
3028 (shell-mode))
3029
3030 (prog1
3031 ;; Run the process.
3032 (apply 'process-file (car args) nil buffer nil (cdr args))
3033 ;; Insert error messages if they were separated.
3034 (when (listp buffer)
3035 (with-current-buffer error-buffer
3036 (insert-file-contents (cadr buffer)))
3037 (delete-file (cadr buffer)))
3038 (if current-buffer-p
3039 ;; This is like exchange-point-and-mark, but doesn't
3040 ;; activate the mark. It is cleaner to avoid activation,
3041 ;; even though the command loop would deactivate the mark
3042 ;; because we inserted text.
3043 (goto-char (prog1 (mark t)
3044 (set-marker (mark-marker) (point)
3045 (current-buffer))))
3046 ;; There's some output, display it.
3047 (when (with-current-buffer output-buffer (> (point-max) (point-min)))
3048 (if (functionp 'display-message-or-buffer)
3049 (tramp-compat-funcall 'display-message-or-buffer output-buffer)
3050 (pop-to-buffer output-buffer))))))))
3051
2962(defun tramp-handle-substitute-in-file-name (filename) 3052(defun tramp-handle-substitute-in-file-name (filename)
2963 "Like `substitute-in-file-name' for Tramp files. 3053 "Like `substitute-in-file-name' for Tramp files.
2964\"//\" and \"/~\" substitute only in the local filename part. 3054\"//\" and \"/~\" substitute only in the local filename part.
@@ -3477,7 +3567,7 @@ Return the local name of the temporary file."
3477 (ignore-errors (delete-file tramp-temp-buffer-file-name)))) 3567 (ignore-errors (delete-file tramp-temp-buffer-file-name))))
3478 3568
3479(add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function) 3569(add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function)
3480(add-hook 'tramp-cache-unload-hook 3570(add-hook 'tramp-unload-hook
3481 (lambda () 3571 (lambda ()
3482 (remove-hook 'kill-buffer-hook 3572 (remove-hook 'kill-buffer-hook
3483 'tramp-delete-temp-file-function))) 3573 'tramp-delete-temp-file-function)))
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 709f01444bf..de46dc19169 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -446,9 +446,10 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
446 (when (eq grep-highlight-matches 'auto-detect) 446 (when (eq grep-highlight-matches 'auto-detect)
447 (grep-compute-defaults)) 447 (grep-compute-defaults))
448 (unless (or (eq grep-highlight-matches 'auto-detect) 448 (unless (or (eq grep-highlight-matches 'auto-detect)
449 ;; Uses font-lock to parse color escapes. (Bug#8084) 449 (null grep-highlight-matches)
450 (null font-lock-mode) 450 ;; Don't output color escapes if they can't be
451 (null grep-highlight-matches)) 451 ;; highlighted with `font-lock-face' by `grep-filter'.
452 (null font-lock-mode))
452 ;; `setenv' modifies `process-environment' let-bound in `compilation-start' 453 ;; `setenv' modifies `process-environment' let-bound in `compilation-start'
453 ;; Any TERM except "dumb" allows GNU grep to use `--color=auto' 454 ;; Any TERM except "dumb" allows GNU grep to use `--color=auto'
454 (setenv "TERM" "emacs-grep") 455 (setenv "TERM" "emacs-grep")
@@ -459,7 +460,7 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
459 ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions 460 ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions
460 (setenv "GREP_COLOR" "01;31") 461 (setenv "GREP_COLOR" "01;31")
461 ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions 462 ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions
462 (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:ml=:cx=:ne")) 463 (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:sl=:cx=:ne"))
463 (set (make-local-variable 'compilation-exit-message-function) 464 (set (make-local-variable 'compilation-exit-message-function)
464 (lambda (status code msg) 465 (lambda (status code msg)
465 (if (eq status 'exit) 466 (if (eq status 'exit)
@@ -480,20 +481,21 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
480This function is called from `compilation-filter-hook'." 481This function is called from `compilation-filter-hook'."
481 (save-excursion 482 (save-excursion
482 (forward-line 0) 483 (forward-line 0)
483 (let ((end (point))) 484 (let ((end (point)) beg)
484 (goto-char compilation-filter-start) 485 (goto-char compilation-filter-start)
485 (forward-line 0) 486 (forward-line 0)
487 (setq beg (point))
486 ;; Only operate on whole lines so we don't get caught with part of an 488 ;; Only operate on whole lines so we don't get caught with part of an
487 ;; escape sequence in one chunk and the rest in another. 489 ;; escape sequence in one chunk and the rest in another.
488 (when (< (point) end) 490 (when (< (point) end)
489 (setq end (copy-marker end)) 491 (setq end (copy-marker end))
490 ;; Highlight grep matches and delete marking sequences. 492 ;; Highlight grep matches and delete marking sequences.
491 (while (re-search-forward "\033\\[01;31m\\(.*?\\)\033\\[[0-9]*m" end 1) 493 (while (re-search-forward "\033\\[0?1;31m\\(.*?\\)\033\\[[0-9]*m" end 1)
492 (replace-match (propertize (match-string 1) 494 (replace-match (propertize (match-string 1)
493 'face nil 'font-lock-face grep-match-face) 495 'face nil 'font-lock-face grep-match-face)
494 t t)) 496 t t))
495 ;; Delete all remaining escape sequences 497 ;; Delete all remaining escape sequences
496 (goto-char compilation-filter-start) 498 (goto-char beg)
497 (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1) 499 (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
498 (replace-match "" t t)))))) 500 (replace-match "" t t))))))
499 501
@@ -987,7 +989,8 @@ This command shares argument histories with \\[lgrep] and \\[grep-find]."
987 dir 989 dir
988 (concat 990 (concat
989 (and grep-find-ignored-directories 991 (and grep-find-ignored-directories
990 (concat (shell-quote-argument "(") 992 (concat "-type d "
993 (shell-quote-argument "(")
991 ;; we should use shell-quote-argument here 994 ;; we should use shell-quote-argument here
992 " -path " 995 " -path "
993 (mapconcat 996 (mapconcat
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4d2f15c69d8..3f923f496b9 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -296,7 +296,7 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
296 :filter (lambda (&rest junk) 296 :filter (lambda (&rest junk)
297 (abbrev-table-menu python-mode-abbrev-table))) 297 (abbrev-table-menu python-mode-abbrev-table)))
298 "-" 298 "-"
299 ["Start interpreter" python-shell 299 ["Start interpreter" run-python
300 :help "Run `inferior' Python in separate buffer"] 300 :help "Run `inferior' Python in separate buffer"]
301 ["Import/reload file" python-load-file 301 ["Import/reload file" python-load-file
302 :help "Load into inferior Python session"] 302 :help "Load into inferior Python session"]
@@ -328,14 +328,6 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
328;; eric has items including: (un)indent, (un)comment, restart script, 328;; eric has items including: (un)indent, (un)comment, restart script,
329;; run script, debug script; also things for profiling, unit testing. 329;; run script, debug script; also things for profiling, unit testing.
330 330
331(defvar python-shell-map
332 (let ((map (copy-keymap comint-mode-map)))
333 (define-key map [tab] 'tab-to-tab-stop)
334 (define-key map "\C-c-" 'py-up-exception)
335 (define-key map "\C-c=" 'py-down-exception)
336 map)
337 "Keymap used in *Python* shell buffers.")
338
339(defvar python-mode-syntax-table 331(defvar python-mode-syntax-table
340 (let ((table (make-syntax-table))) 332 (let ((table (make-syntax-table)))
341 ;; Give punctuation syntax to ASCII that normally has symbol 333 ;; Give punctuation syntax to ASCII that normally has symbol
@@ -1345,7 +1337,7 @@ local value.")
1345 (define-key map "\C-c\C-l" 'python-load-file) 1337 (define-key map "\C-c\C-l" 'python-load-file)
1346 (define-key map "\C-c\C-v" 'python-check) 1338 (define-key map "\C-c\C-v" 'python-check)
1347 ;; Note that we _can_ still use these commands which send to the 1339 ;; Note that we _can_ still use these commands which send to the
1348 ;; Python process even at the prompt iff we have a normal prompt, 1340 ;; Python process even at the prompt if we have a normal prompt,
1349 ;; i.e. '>>> ' and not '... '. See the comment before 1341 ;; i.e. '>>> ' and not '... '. See the comment before
1350 ;; python-send-region. Fixme: uncomment these if we address that. 1342 ;; python-send-region. Fixme: uncomment these if we address that.
1351 1343
diff --git a/lisp/subr.el b/lisp/subr.el
index b49a20e7f6e..a2676b1173d 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2254,7 +2254,7 @@ is nil and `use-dialog-box' is non-nil."
2254 (listp last-nonmenu-event) 2254 (listp last-nonmenu-event)
2255 use-dialog-box) 2255 use-dialog-box)
2256 (setq answer 2256 (setq answer
2257 (x-popup-dialog t `(,prompt ("yes" . act) ("No" . skip)))) 2257 (x-popup-dialog t `(,prompt ("Yes" . act) ("No" . skip))))
2258 (setq prompt (concat prompt 2258 (setq prompt (concat prompt
2259 (if (eq ?\s (aref prompt (1- (length prompt)))) 2259 (if (eq ?\s (aref prompt (1- (length prompt))))
2260 "" " ") 2260 "" " ")
diff --git a/lisp/window.el b/lisp/window.el
index d078fbec35d..5272841a9c7 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2291,29 +2291,45 @@ frame."
2291 (setq window (window-atom-root window)))) 2291 (setq window (window-atom-root window))))
2292 (let ((parent (window-parent window)) 2292 (let ((parent (window-parent window))
2293 (frame (window-frame window)) 2293 (frame (window-frame window))
2294 (buffer (window-buffer window))
2294 (dedicated (and (window-buffer window) (window-dedicated-p window))) 2295 (dedicated (and (window-buffer window) (window-dedicated-p window)))
2295 (quit-restore (window-parameter window 'quit-restore))) 2296 (quit-restore (window-parameter window 'quit-restore)))
2296 (cond 2297 (cond
2297 ((frame-root-window-p window) 2298 ((frame-root-window-p window)
2299 ;; Don't delete FRAME if `frame-auto-delete' is nil.
2298 (when (and (or (eq frame-auto-delete t) 2300 (when (and (or (eq frame-auto-delete t)
2299 (and (eq frame-auto-delete 'automatic) 2301 (and (eq frame-auto-delete 'automatic)
2302 ;; Delete FRAME only if it's either dedicated
2303 ;; or quit-restore's car is `new-frame' and
2304 ;; WINDOW still displays the same buffer
2300 (or dedicated 2305 (or dedicated
2301 (and (eq (car-safe quit-restore) 'new-frame) 2306 (and (eq (car-safe quit-restore) 'new-frame)
2302 (eq (nth 1 quit-restore) 2307 (eq (nth 1 quit-restore)
2303 (window-buffer window)))))) 2308 (window-buffer window))))))
2309 ;; Don't delete FRAME if we have another buffer in
2310 ;; WINDOW's previous buffers. Bug#9419.
2311 (or (not (window-prev-buffers window))
2312 (eq (caar (window-prev-buffers window)) buffer))
2313 ;; Don't try to delete FRAME when there are no other
2314 ;; visible frames left.
2304 (other-visible-frames-p frame)) 2315 (other-visible-frames-p frame))
2305 ;; WINDOW is the root window of its frame. Return `frame' but
2306 ;; only if WINDOW is (1) either dedicated or quit-restore's car
2307 ;; is `new-frame' and the window still displays the same buffer
2308 ;; and (2) there are other frames left.
2309 'frame)) 2316 'frame))
2310 ((and (not ignore-window-parameters) 2317 ;; Don't delete WINDOW if we find another buffer in WINDOW's
2311 (eq (window-parameter window 'window-side) 'none) 2318 ;; previous buffers.
2312 (or (not parent) 2319 ((and (or (not (window-prev-buffers window))
2313 (not (eq (window-parameter parent 'window-side) 'none)))) 2320 (eq (caar (window-prev-buffers window)) buffer))
2314 ;; Can't delete last main window. 2321 ;; Delete WINDOW only if it's dedicated or quit-restore's car
2315 nil) 2322 ;; is `new-frame' or `new-window' and it still displays the
2316 (t)))) 2323 ;; same buffer.
2324 (or dedicated
2325 (and (memq (car-safe quit-restore) '(new-window new-frame))
2326 (eq (nth 1 quit-restore) (window-buffer window))))
2327 ;; Don't delete the last main window.
2328 (or ignore-window-parameters
2329 (not (eq (window-parameter window 'window-side) 'none))
2330 (and parent
2331 (eq (window-parameter parent 'window-side) 'none))))
2332 t))))
2317 2333
2318(defun window-or-subwindow-p (subwindow window) 2334(defun window-or-subwindow-p (subwindow window)
2319 "Return t if SUBWINDOW is either WINDOW or a subwindow of WINDOW." 2335 "Return t if SUBWINDOW is either WINDOW or a subwindow of WINDOW."
@@ -4714,7 +4730,10 @@ return the window on the new frame; otherwise return nil."
4714 (setq frame (funcall fun)) 4730 (setq frame (funcall fun))
4715 (setq window (frame-selected-window frame))) 4731 (setq window (frame-selected-window frame)))
4716 (display-buffer-record-window 'pop-up-frame window buffer) 4732 (display-buffer-record-window 'pop-up-frame window buffer)
4717 (window--display-buffer-2 buffer window)))) 4733 (window--display-buffer-2 buffer window)
4734 ;; Reset list of WINDOW's previous buffers to nil.
4735 (set-window-prev-buffers window nil)
4736 window)))
4718 4737
4719(defun display-buffer-pop-up-window (buffer alist) 4738(defun display-buffer-pop-up-window (buffer alist)
4720 "Display BUFFER by popping up a new window. 4739 "Display BUFFER by popping up a new window.
@@ -4737,7 +4756,10 @@ If sucessful, return the new window; otherwise return nil."
4737 (window--try-to-split-window 4756 (window--try-to-split-window
4738 (get-lru-window frame t))))) 4757 (get-lru-window frame t)))))
4739 (display-buffer-record-window 'pop-up-window window buffer) 4758 (display-buffer-record-window 'pop-up-window window buffer)
4740 (window--display-buffer-2 buffer window)))) 4759 (window--display-buffer-2 buffer window)
4760 ;; Reset list of WINDOW's previous buffers to nil.
4761 (set-window-prev-buffers window nil)
4762 window)))
4741 4763
4742;; This display action function groups together some lower-level ones: 4764;; This display action function groups together some lower-level ones:
4743(defun display-buffer-reuse-or-pop-window (buffer alist) 4765(defun display-buffer-reuse-or-pop-window (buffer alist)
diff --git a/nt/ChangeLog b/nt/ChangeLog
index edbd1a1c1d4..8c2ca056aa1 100644
--- a/nt/ChangeLog
+++ b/nt/ChangeLog
@@ -1,3 +1,7 @@
12011-09-04 Paul Eggert <eggert@cs.ucla.edu>
2
3 * config.nt (HAVE_SNPRINTF): New macro.
4
12011-07-28 Paul Eggert <eggert@cs.ucla.edu> 52011-07-28 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 Assume freestanding C89 headers, string.h, stdlib.h. 7 Assume freestanding C89 headers, string.h, stdlib.h.
diff --git a/nt/config.nt b/nt/config.nt
index 3436bc989e0..ae3807538c0 100644
--- a/nt/config.nt
+++ b/nt/config.nt
@@ -240,6 +240,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
240#define HAVE_SETSOCKOPT 1 240#define HAVE_SETSOCKOPT 1
241#define HAVE_GETSOCKNAME 1 241#define HAVE_GETSOCKNAME 1
242#define HAVE_GETPEERNAME 1 242#define HAVE_GETPEERNAME 1
243#define HAVE_SNPRINTF 1
243#define HAVE_LANGINFO_CODESET 1 244#define HAVE_LANGINFO_CODESET 1
244/* Local (unix) sockets are not supported. */ 245/* Local (unix) sockets are not supported. */
245#undef HAVE_SYS_UN_H 246#undef HAVE_SYS_UN_H
diff --git a/src/ChangeLog b/src/ChangeLog
index a3c850e3b7f..88065dd3231 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,4 +1,4 @@
12011-09-03 Paul Eggert <eggert@cs.ucla.edu> 12011-09-05 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * fileio.c: Fix bugs with large file offsets (Bug#9428). 3 * fileio.c: Fix bugs with large file offsets (Bug#9428).
4 The previous code assumed that file offsets (off_t values) fit in 4 The previous code assumed that file offsets (off_t values) fit in
@@ -17,6 +17,158 @@
17 (Fwrite_region): Don't assume off_t fits into 'long'. 17 (Fwrite_region): Don't assume off_t fits into 'long'.
18 * buffer.h (struct buffer.modtime_size): Now off_t, not EMACS_INT. 18 * buffer.h (struct buffer.modtime_size): Now off_t, not EMACS_INT.
19 19
202011-09-05 Michael Albinus <michael.albinus@gmx.de>
21
22 * dbusbind.c (xd_signature_cat): Rename from signature_cat.
23
242011-09-04 Paul Eggert <eggert@cs.ucla.edu>
25
26 sprintf-related integer and memory overflow issues (Bug#9412).
27
28 * doprnt.c (doprnt): Support printing ptrdiff_t and intmax_t values.
29 (esprintf, exprintf, evxprintf): New functions.
30 * keyboard.c (command_loop_level): Now EMACS_INT, not int.
31 (cmd_error): kbd macro iterations count is now EMACS_INT, not int.
32 (modify_event_symbol): Do not assume that the length of
33 name_alist_or_stem is safe to alloca and fits in int.
34 (Fexecute_extended_command): Likewise for function name and binding.
35 (Frecursion_depth): Wrap around reliably on integer overflow.
36 * keymap.c (push_key_description): First arg is now EMACS_INT, not int,
37 since some callers pass EMACS_INT values.
38 (Fsingle_key_description): Don't crash if symbol name contains more
39 than MAX_ALLOCA bytes.
40 * minibuf.c (minibuf_level): Now EMACS_INT, not int.
41 (get_minibuffer): Arg is now EMACS_INT, not int.
42 * lisp.h (get_minibuffer, push_key_description): Reflect API changes.
43 (esprintf, exprintf, evxprintf): New decls.
44 * window.h (command_loop_level, minibuf_level): Reflect API changes.
45
46 * dbusbind.c (signature_cat): New function.
47 (xd_signature, Fdbus_register_signal):
48 Do not overrun buffer; instead, report string overflow.
49
50 * dispnew.c (add_window_display_history): Don't overrun buffer.
51 Truncate instead; this is OK since it's just a log.
52
53 * editfns.c (Fcurrent_time_zone): Don't overrun buffer
54 even if the time zone offset is outlandishly large.
55 Don't mishandle offset == INT_MIN.
56
57 * emacs.c (main) [NS_IMPL_COCOA]: Don't overrun buffer
58 when creating daemon; the previous buffer-overflow check was incorrect.
59
60 * eval.c (verror): Simplify by rewriting in terms of evxprintf,
61 which has the guts of the old verror function.
62
63 * filelock.c (lock_file_1, lock_file): Don't blindly alloca long name;
64 use SAFE_ALLOCA instead. Use esprintf to avoid int-overflow issues.
65
66 * font.c: Include <float.h>, for DBL_MAX_10_EXP.
67 (font_unparse_xlfd): Don't blindly alloca long strings.
68 Don't assume XINT result fits in int, or that XFLOAT_DATA * 10
69 fits in int, when using sprintf. Use single snprintf to count
70 length of string rather than counting it via multiple sprintfs;
71 that's simpler and more reliable.
72 (font_unparse_fcname): Use it to avoid sprintf buffer overrun.
73 (generate_otf_features) [0 && HAVE_LIBOTF]: Use esprintf, not
74 sprintf, in case result does not fit in int.
75
76 * fontset.c (num_auto_fontsets): Now printmax_t, not int.
77 (fontset_from_font): Print it.
78
79 * frame.c (tty_frame_count): Now printmax_t, not int.
80 (make_terminal_frame, set_term_frame_name): Print it.
81 (x_report_frame_params): In X, window IDs are unsigned long,
82 not signed long, so print them as unsigned.
83 (validate_x_resource_name): Check for implausibly long names,
84 and don't assume name length fits in 'int'.
85 (x_get_resource_string): Don't blindly alloca invocation name;
86 use SAFE_ALLOCA. Use esprintf, not sprintf, in case result does
87 not fit in int.
88
89 * gtkutil.c: Include <float.h>, for DBL_MAX_10_EXP.
90 (xg_check_special_colors, xg_set_geometry):
91 Make sprintf buffers a bit bigger, to avoid potential buffer overrun.
92
93 * lread.c (dir_warning): Don't blindly alloca buffer; use SAFE_ALLOCA.
94 Use esprintf, not sprintf, in case result does not fit in int.
95
96 * macros.c (executing_kbd_macro_iterations): Now EMACS_INT, not int.
97 (Fend_kbd_macro): Don't mishandle MOST_NEGATIVE_FIXNUM by treating
98 it as a large positive number.
99 (Fexecute_kbd_macro): Don't assume repeat count fits in int.
100 * macros.h (executing_kbd_macro_iterations): Now EMACS_INT, not int.
101
102 * nsterm.m ((NSSize)windowWillResize): Use esprintf, not sprintf,
103 in case result does not fit in int.
104
105 * print.c (float_to_string): Detect width overflow more reliably.
106 (print_object): Make sprintf buffer a bit bigger, to avoid potential
107 buffer overrun. Don't assume list length fits in 'int'. Treat
108 print length of 0 as 0, not as infinity; to be consistent with other
109 uses of print length in this function. Don't overflow print length
110 index. Don't assume hash table size fits in 'long', or that
111 vectorlike size fits in 'unsigned long'.
112
113 * process.c (make_process): Use printmax_t, not int, to format
114 process-name gensyms.
115
116 * sysdep.c (snprintf) [! HAVE_SNPRINTF]: New function.
117
118 * term.c (produce_glyphless_glyph): Make sprintf buffer a bit bigger
119 to avoid potential buffer overrun.
120
121 * xfaces.c (x_update_menu_appearance): Don't overrun buffer
122 if X resource line is longer than 512 bytes.
123
124 * xfns.c (x_window): Make sprintf buffer a bit bigger
125 to avoid potential buffer overrun.
126
127 * xterm.c (x_io_error_quitter): Don't overrun sprintf buffer.
128
129 * xterm.h (x_check_errors): Add ATTRIBUTE_FORMAT_PRINTF.
130
1312011-09-04 Paul Eggert <eggert@cs.ucla.edu>
132
133 Integer overflow fixes for scrolling, etc.
134 Without these, Emacs silently mishandles large integers sometimes.
135 For example, "C-u 4294967297 M-x recenter" was treated as if
136 it were "C-u 1 M-x recenter" on a typical 64-bit host.
137
138 * xdisp.c (try_window_id): Check Emacs fixnum range before
139 converting to 'int'.
140
141 * window.c (window_scroll_line_based, Frecenter):
142 Check that an Emacs fixnum is in range before assigning it to 'int'.
143 (Frecenter, Fmove_to_window_line): Use EMACS_INT, not int, for
144 values converted from Emacs fixnums.
145 (Frecenter): Don't wrap around a line count if it is out of 'int'
146 range; instead, treat it as an extreme value.
147 (Fset_window_configuration, compare_window_configurations):
148 Use ptrdiff_t, not int, for index that might exceed 2 GiB.
149
150 * search.c (Freplace_match): Use ptrdiff_t, not int, for indexes
151 that can exceed INT_MAX. Check that EMACS_INT value is in range
152 before assigning it to the (possibly-narrower) index.
153 (match_limit): Don't assume that a fixnum can fit in 'int'.
154
155 * print.c (print_object): Use ptrdiff_t, not int, for index that can
156 exceed INT_MAX.
157
158 * indent.c (position_indentation): Now takes ptrdiff_t, not int.
159 (Fvertical_motion): Don't wrap around LINES values that don't fit
160 in 'int'. Instead, treat them as extreme values. This is good
161 enough for windows, which can't have more than INT_MAX lines anyway.
162
1632011-09-03 Lars Magne Ingebrigtsen <larsi@gnus.org>
164
165 * Require libxml/parser.h to avoid compilation warning.
166
167 * emacs.c (shut_down_emacs): Call xmlCleanupParser on shutdown.
168
169 * xml.c (parse_region): Don't call xmlCleanupParser after parsing,
170 since this reportedly can destroy thread storage.
171
202011-08-30 Chong Yidong <cyd@stupidchicken.com> 1722011-08-30 Chong Yidong <cyd@stupidchicken.com>
21 173
22 * syntax.c (find_defun_start): Update all cache variables if 174 * syntax.c (find_defun_start): Update all cache variables if
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4828f4e968d..2a38d15873c 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -259,6 +259,18 @@ xd_symbol_to_dbus_type (Lisp_Object object)
259 } \ 259 } \
260 while (0) 260 while (0)
261 261
262/* Append to SIGNATURE a copy of X, making sure SIGNATURE does
263 not become too long. */
264static void
265xd_signature_cat (char *signature, char const *x)
266{
267 ptrdiff_t siglen = strlen (signature);
268 ptrdiff_t xlen = strlen (x);
269 if (DBUS_MAXIMUM_SIGNATURE_LENGTH - xlen <= siglen)
270 string_overflow ();
271 strcat (signature, x);
272}
273
262/* Compute SIGNATURE of OBJECT. It must have a form that it can be 274/* Compute SIGNATURE of OBJECT. It must have a form that it can be
263 used in dbus_message_iter_open_container. DTYPE is the DBusType 275 used in dbus_message_iter_open_container. DTYPE is the DBusType
264 the object is related to. It is passed as argument, because it 276 the object is related to. It is passed as argument, because it
@@ -271,6 +283,8 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
271{ 283{
272 unsigned int subtype; 284 unsigned int subtype;
273 Lisp_Object elt; 285 Lisp_Object elt;
286 char const *subsig;
287 int subsiglen;
274 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 288 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH];
275 289
276 elt = object; 290 elt = object;
@@ -328,12 +342,13 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
328 if (NILP (elt)) 342 if (NILP (elt))
329 { 343 {
330 subtype = DBUS_TYPE_STRING; 344 subtype = DBUS_TYPE_STRING;
331 strcpy (x, DBUS_TYPE_STRING_AS_STRING); 345 subsig = DBUS_TYPE_STRING_AS_STRING;
332 } 346 }
333 else 347 else
334 { 348 {
335 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 349 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
336 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 350 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
351 subsig = x;
337 } 352 }
338 353
339 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the 354 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the
@@ -342,7 +357,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
342 if ((subtype == DBUS_TYPE_SIGNATURE) 357 if ((subtype == DBUS_TYPE_SIGNATURE)
343 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt))) 358 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt)))
344 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 359 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
345 strcpy (x, SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)))); 360 subsig = SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)));
346 361
347 while (!NILP (elt)) 362 while (!NILP (elt))
348 { 363 {
@@ -351,7 +366,10 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
351 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 366 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
352 } 367 }
353 368
354 sprintf (signature, "%c%s", dtype, x); 369 subsiglen = snprintf (signature, DBUS_MAXIMUM_SIGNATURE_LENGTH,
370 "%c%s", dtype, subsig);
371 if (! (0 <= subsiglen && subsiglen < DBUS_MAXIMUM_SIGNATURE_LENGTH))
372 string_overflow ();
355 break; 373 break;
356 374
357 case DBUS_TYPE_VARIANT: 375 case DBUS_TYPE_VARIANT:
@@ -383,10 +401,10 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
383 { 401 {
384 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 402 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
385 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 403 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
386 strcat (signature, x); 404 xd_signature_cat (signature, x);
387 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 405 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
388 } 406 }
389 strcat (signature, DBUS_STRUCT_END_CHAR_AS_STRING); 407 xd_signature_cat (signature, DBUS_STRUCT_END_CHAR_AS_STRING);
390 break; 408 break;
391 409
392 case DBUS_TYPE_DICT_ENTRY: 410 case DBUS_TYPE_DICT_ENTRY:
@@ -407,7 +425,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
407 elt = XD_NEXT_VALUE (elt); 425 elt = XD_NEXT_VALUE (elt);
408 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 426 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
409 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 427 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
410 strcat (signature, x); 428 xd_signature_cat (signature, x);
411 429
412 if (!XD_BASIC_DBUS_TYPE (subtype)) 430 if (!XD_BASIC_DBUS_TYPE (subtype))
413 wrong_type_argument (intern ("D-Bus"), CAR_SAFE (XD_NEXT_VALUE (elt))); 431 wrong_type_argument (intern ("D-Bus"), CAR_SAFE (XD_NEXT_VALUE (elt)));
@@ -416,14 +434,14 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
416 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 434 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
417 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 435 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
418 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 436 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
419 strcat (signature, x); 437 xd_signature_cat (signature, x);
420 438
421 if (!NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 439 if (!NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
422 wrong_type_argument (intern ("D-Bus"), 440 wrong_type_argument (intern ("D-Bus"),
423 CAR_SAFE (CDR_SAFE (XD_NEXT_VALUE (elt)))); 441 CAR_SAFE (CDR_SAFE (XD_NEXT_VALUE (elt))));
424 442
425 /* Closing signature. */ 443 /* Closing signature. */
426 strcat (signature, DBUS_DICT_ENTRY_END_CHAR_AS_STRING); 444 xd_signature_cat (signature, DBUS_DICT_ENTRY_END_CHAR_AS_STRING);
427 break; 445 break;
428 446
429 default: 447 default:
@@ -2026,7 +2044,7 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2026 DBusConnection *connection; 2044 DBusConnection *connection;
2027 ptrdiff_t i; 2045 ptrdiff_t i;
2028 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2046 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2029 char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2047 int rulelen;
2030 DBusError derror; 2048 DBusError derror;
2031 2049
2032 /* Check parameters. */ 2050 /* Check parameters. */
@@ -2071,32 +2089,43 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2071 connection = xd_initialize (bus, TRUE); 2089 connection = xd_initialize (bus, TRUE);
2072 2090
2073 /* Create a rule to receive related signals. */ 2091 /* Create a rule to receive related signals. */
2074 sprintf (rule, 2092 rulelen = snprintf (rule, sizeof rule,
2075 "type='signal',interface='%s',member='%s'", 2093 "type='signal',interface='%s',member='%s'",
2076 SDATA (interface), 2094 SDATA (interface),
2077 SDATA (signal)); 2095 SDATA (signal));
2096 if (! (0 <= rulelen && rulelen < sizeof rule))
2097 string_overflow ();
2078 2098
2079 /* Add unique name and path to the rule if they are non-nil. */ 2099 /* Add unique name and path to the rule if they are non-nil. */
2080 if (!NILP (uname)) 2100 if (!NILP (uname))
2081 { 2101 {
2082 sprintf (x, ",sender='%s'", SDATA (uname)); 2102 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2083 strcat (rule, x); 2103 ",sender='%s'", SDATA (uname));
2104 if (! (0 <= len && len < sizeof rule - rulelen))
2105 string_overflow ();
2106 rulelen += len;
2084 } 2107 }
2085 2108
2086 if (!NILP (path)) 2109 if (!NILP (path))
2087 { 2110 {
2088 sprintf (x, ",path='%s'", SDATA (path)); 2111 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2089 strcat (rule, x); 2112 ",path='%s'", SDATA (path));
2113 if (! (0 <= len && len < sizeof rule - rulelen))
2114 string_overflow ();
2115 rulelen += len;
2090 } 2116 }
2091 2117
2092 /* Add arguments to the rule if they are non-nil. */ 2118 /* Add arguments to the rule if they are non-nil. */
2093 for (i = 6; i < nargs; ++i) 2119 for (i = 6; i < nargs; ++i)
2094 if (!NILP (args[i])) 2120 if (!NILP (args[i]))
2095 { 2121 {
2122 int len;
2096 CHECK_STRING (args[i]); 2123 CHECK_STRING (args[i]);
2097 sprintf (x, ",arg%"pD"d='%s'", i - 6, 2124 len = snprintf (rule + rulelen, sizeof rule - rulelen,
2098 SDATA (args[i])); 2125 ",arg%"pD"d='%s'", i - 6, SDATA (args[i]));
2099 strcat (rule, x); 2126 if (! (0 <= len && len < sizeof rule - rulelen))
2127 string_overflow ();
2128 rulelen += len;
2100 } 2129 }
2101 2130
2102 /* Add the rule to the bus. */ 2131 /* Add the rule to the bus. */
diff --git a/src/dispnew.c b/src/dispnew.c
index e96583e0025..5c28d014819 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -272,15 +272,16 @@ add_window_display_history (struct window *w, const char *msg, int paused_p)
272 buf = redisplay_history[history_idx].trace; 272 buf = redisplay_history[history_idx].trace;
273 ++history_idx; 273 ++history_idx;
274 274
275 sprintf (buf, "%"pMu": window %p (`%s')%s\n", 275 snprintf (buf, sizeof redisplay_history[0].trace,
276 history_tick++, 276 "%"pMu": window %p (`%s')%s\n%s",
277 w, 277 history_tick++,
278 ((BUFFERP (w->buffer) 278 w,
279 && STRINGP (BVAR (XBUFFER (w->buffer), name))) 279 ((BUFFERP (w->buffer)
280 ? SSDATA (BVAR (XBUFFER (w->buffer), name)) 280 && STRINGP (BVAR (XBUFFER (w->buffer), name)))
281 : "???"), 281 ? SSDATA (BVAR (XBUFFER (w->buffer), name))
282 paused_p ? " ***paused***" : ""); 282 : "???"),
283 strcat (buf, msg); 283 paused_p ? " ***paused***" : "",
284 msg);
284} 285}
285 286
286 287
diff --git a/src/doprnt.c b/src/doprnt.c
index 79f9f36e461..638fa4d6312 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -70,9 +70,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
70 %<flags><width><precision><length>character 70 %<flags><width><precision><length>character
71 71
72 where flags is [+ -0], width is [0-9]+, precision is .[0-9]+, and length 72 where flags is [+ -0], width is [0-9]+, precision is .[0-9]+, and length
73 is empty or l or the value of the pI macro. Also, %% in a format 73 is empty or l or the value of the pD or pI or pMd (sans "d") macros.
74 stands for a single % in the output. A % that does not introduce a 74 Also, %% in a format stands for a single % in the output. A % that
75 valid %-sequence causes undefined behavior. 75 does not introduce a valid %-sequence causes undefined behavior.
76 76
77 The + flag character inserts a + before any positive number, while a space 77 The + flag character inserts a + before any positive number, while a space
78 inserts a space before any positive number; these flags only affect %d, %o, 78 inserts a space before any positive number; these flags only affect %d, %o,
@@ -85,8 +85,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
85 modifier: it is supported for %d, %o, and %x conversions of integral 85 modifier: it is supported for %d, %o, and %x conversions of integral
86 arguments, must immediately precede the conversion specifier, and means that 86 arguments, must immediately precede the conversion specifier, and means that
87 the respective argument is to be treated as `long int' or `unsigned long 87 the respective argument is to be treated as `long int' or `unsigned long
88 int'. Similarly, the value of the pI macro means to use EMACS_INT or 88 int'. Similarly, the value of the pD macro means to use ptrdiff_t,
89 EMACS_UINT and the empty length modifier means `int' or `unsigned int'. 89 the value of the pI macro means to use EMACS_INT or EMACS_UINT, the
90 value of the pMd etc. macros means to use intmax_t or uintmax_t,
91 and the empty length modifier means `int' or `unsigned int'.
90 92
91 The width specifier supplies a lower limit for the length of the printed 93 The width specifier supplies a lower limit for the length of the printed
92 representation. The padding, if any, normally goes on the left, but it goes 94 representation. The padding, if any, normally goes on the left, but it goes
@@ -173,8 +175,17 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
173 { 175 {
174 ptrdiff_t size_bound = 0; 176 ptrdiff_t size_bound = 0;
175 EMACS_INT width; /* Columns occupied by STRING on display. */ 177 EMACS_INT width; /* Columns occupied by STRING on display. */
176 int long_flag = 0; 178 enum {
177 int pIlen = sizeof pI - 1; 179 pDlen = sizeof pD - 1,
180 pIlen = sizeof pI - 1,
181 pMlen = sizeof pMd - 2
182 };
183 enum {
184 no_modifier, long_modifier, pD_modifier, pI_modifier, pM_modifier
185 } length_modifier = no_modifier;
186 static char const modifier_len[] = { 0, 1, pDlen, pIlen, pMlen };
187 int maxmlen = max (max (1, pDlen), max (pIlen, pMlen));
188 int mlen;
178 189
179 fmt++; 190 fmt++;
180 /* Copy this one %-spec into fmtcpy. */ 191 /* Copy this one %-spec into fmtcpy. */
@@ -213,19 +224,26 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
213 fmt++; 224 fmt++;
214 } 225 }
215 226
216 if (0 < pIlen && pIlen <= format_end - fmt 227 /* Check for the length modifiers in textual length order, so
217 && memcmp (fmt, pI, pIlen) == 0) 228 that longer modifiers override shorter ones. */
229 for (mlen = 1; mlen <= maxmlen; mlen++)
218 { 230 {
219 long_flag = 2; 231 if (format_end - fmt < mlen)
220 memcpy (string, fmt + 1, pIlen); 232 break;
221 string += pIlen; 233 if (mlen == 1 && *fmt == 'l')
222 fmt += pIlen; 234 length_modifier = long_modifier;
223 } 235 if (mlen == pDlen && memcmp (fmt, pD, pDlen) == 0)
224 else if (fmt < format_end && *fmt == 'l') 236 length_modifier = pD_modifier;
225 { 237 if (mlen == pIlen && memcmp (fmt, pI, pIlen) == 0)
226 long_flag = 1; 238 length_modifier = pI_modifier;
227 *string++ = *++fmt; 239 if (mlen == pMlen && memcmp (fmt, pMd, pMlen) == 0)
240 length_modifier = pM_modifier;
228 } 241 }
242
243 mlen = modifier_len[length_modifier];
244 memcpy (string, fmt + 1, mlen);
245 string += mlen;
246 fmt += mlen;
229 *string = 0; 247 *string = 0;
230 248
231 /* Make the size bound large enough to handle floating point formats 249 /* Make the size bound large enough to handle floating point formats
@@ -252,55 +270,78 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
252/* case 'b': */ 270/* case 'b': */
253 case 'l': 271 case 'l':
254 case 'd': 272 case 'd':
255 { 273 switch (length_modifier)
256 int i; 274 {
257 long l; 275 case no_modifier:
258
259 if (1 < long_flag)
260 { 276 {
261 EMACS_INT ll = va_arg (ap, EMACS_INT); 277 int v = va_arg (ap, int);
262 sprintf (sprintf_buffer, fmtcpy, ll); 278 sprintf (sprintf_buffer, fmtcpy, v);
263 } 279 }
264 else if (long_flag) 280 break;
281 case long_modifier:
265 { 282 {
266 l = va_arg(ap, long); 283 long v = va_arg (ap, long);
267 sprintf (sprintf_buffer, fmtcpy, l); 284 sprintf (sprintf_buffer, fmtcpy, v);
268 } 285 }
269 else 286 break;
287 case pD_modifier:
288 signed_pD_modifier:
270 { 289 {
271 i = va_arg(ap, int); 290 ptrdiff_t v = va_arg (ap, ptrdiff_t);
272 sprintf (sprintf_buffer, fmtcpy, i); 291 sprintf (sprintf_buffer, fmtcpy, v);
273 } 292 }
274 /* Now copy into final output, truncating as necessary. */ 293 break;
275 string = sprintf_buffer; 294 case pI_modifier:
276 goto doit; 295 {
277 } 296 EMACS_INT v = va_arg (ap, EMACS_INT);
297 sprintf (sprintf_buffer, fmtcpy, v);
298 }
299 break;
300 case pM_modifier:
301 {
302 intmax_t v = va_arg (ap, intmax_t);
303 sprintf (sprintf_buffer, fmtcpy, v);
304 }
305 break;
306 }
307 /* Now copy into final output, truncating as necessary. */
308 string = sprintf_buffer;
309 goto doit;
278 310
279 case 'o': 311 case 'o':
280 case 'x': 312 case 'x':
281 { 313 switch (length_modifier)
282 unsigned u; 314 {
283 unsigned long ul; 315 case no_modifier:
284
285 if (1 < long_flag)
286 { 316 {
287 EMACS_UINT ull = va_arg (ap, EMACS_UINT); 317 unsigned v = va_arg (ap, unsigned);
288 sprintf (sprintf_buffer, fmtcpy, ull); 318 sprintf (sprintf_buffer, fmtcpy, v);
289 } 319 }
290 else if (long_flag) 320 break;
321 case long_modifier:
291 { 322 {
292 ul = va_arg(ap, unsigned long); 323 unsigned long v = va_arg (ap, unsigned long);
293 sprintf (sprintf_buffer, fmtcpy, ul); 324 sprintf (sprintf_buffer, fmtcpy, v);
294 } 325 }
295 else 326 break;
327 case pD_modifier:
328 goto signed_pD_modifier;
329 case pI_modifier:
296 { 330 {
297 u = va_arg(ap, unsigned); 331 EMACS_UINT v = va_arg (ap, EMACS_UINT);
298 sprintf (sprintf_buffer, fmtcpy, u); 332 sprintf (sprintf_buffer, fmtcpy, v);
299 } 333 }
300 /* Now copy into final output, truncating as necessary. */ 334 break;
301 string = sprintf_buffer; 335 case pM_modifier:
302 goto doit; 336 {
303 } 337 uintmax_t v = va_arg (ap, uintmax_t);
338 sprintf (sprintf_buffer, fmtcpy, v);
339 }
340 break;
341 }
342 /* Now copy into final output, truncating as necessary. */
343 string = sprintf_buffer;
344 goto doit;
304 345
305 case 'f': 346 case 'f':
306 case 'e': 347 case 'e':
@@ -426,3 +467,61 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
426 SAFE_FREE (); 467 SAFE_FREE ();
427 return bufptr - buffer; 468 return bufptr - buffer;
428} 469}
470
471/* Format to an unbounded buffer BUF. This is like sprintf, except it
472 is not limited to returning an 'int' so it doesn't have a silly 2
473 GiB limit on typical 64-bit hosts. However, it is limited to the
474 Emacs-style formats that doprnt supports.
475
476 Return the number of bytes put into BUF, excluding the terminating
477 '\0'. */
478ptrdiff_t
479esprintf (char *buf, char const *format, ...)
480{
481 ptrdiff_t nbytes;
482 va_list ap;
483 va_start (ap, format);
484 nbytes = doprnt (buf, TYPE_MAXIMUM (ptrdiff_t), format, 0, ap);
485 va_end (ap);
486 return nbytes;
487}
488
489/* Format to buffer *BUF of positive size *BUFSIZE, reallocating *BUF
490 and updating *BUFSIZE if the buffer is too small, and otherwise
491 behaving line esprintf. When reallocating, free *BUF unless it is
492 equal to NONHEAPBUF, and if BUFSIZE_MAX is nonnegative then signal
493 memory exhaustion instead of growing the buffer size past
494 BUFSIZE_MAX. */
495ptrdiff_t
496exprintf (char **buf, ptrdiff_t *bufsize,
497 char const *nonheapbuf, ptrdiff_t bufsize_max,
498 char const *format, ...)
499{
500 ptrdiff_t nbytes;
501 va_list ap;
502 va_start (ap, format);
503 nbytes = evxprintf (buf, bufsize, nonheapbuf, bufsize_max, format, ap);
504 va_end (ap);
505 return nbytes;
506}
507
508/* Act like exprintf, except take a va_list. */
509ptrdiff_t
510evxprintf (char **buf, ptrdiff_t *bufsize,
511 char const *nonheapbuf, ptrdiff_t bufsize_max,
512 char const *format, va_list ap)
513{
514 for (;;)
515 {
516 ptrdiff_t nbytes;
517 va_list ap_copy;
518 va_copy (ap_copy, ap);
519 nbytes = doprnt (*buf, *bufsize, format, 0, ap_copy);
520 va_end (ap_copy);
521 if (nbytes < *bufsize - 1)
522 return nbytes;
523 if (*buf != nonheapbuf)
524 xfree (*buf);
525 *buf = xpalloc (NULL, bufsize, 1, bufsize_max, 1);
526 }
527}
diff --git a/src/editfns.c b/src/editfns.c
index 6759016766f..580298c6e7d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2014,7 +2014,7 @@ the data it can't find. */)
2014 { 2014 {
2015 int offset = tm_diff (t, &gmt); 2015 int offset = tm_diff (t, &gmt);
2016 char *s = 0; 2016 char *s = 0;
2017 char buf[6]; 2017 char buf[sizeof "+00" + INT_STRLEN_BOUND (int)];
2018 2018
2019#ifdef HAVE_TM_ZONE 2019#ifdef HAVE_TM_ZONE
2020 if (t->tm_zone) 2020 if (t->tm_zone)
@@ -2029,7 +2029,8 @@ the data it can't find. */)
2029 if (!s) 2029 if (!s)
2030 { 2030 {
2031 /* No local time zone name is available; use "+-NNNN" instead. */ 2031 /* No local time zone name is available; use "+-NNNN" instead. */
2032 int am = (offset < 0 ? -offset : offset) / 60; 2032 int m = offset / 60;
2033 int am = offset < 0 ? - m : m;
2033 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60); 2034 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
2034 s = buf; 2035 s = buf;
2035 } 2036 }
diff --git a/src/emacs.c b/src/emacs.c
index 7039f063dc2..83ad8d95156 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -82,6 +82,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
82#include <sys/personality.h> 82#include <sys/personality.h>
83#endif 83#endif
84 84
85#ifdef HAVE_LIBXML2
86#include <libxml/parser.h>
87#endif
88
85#ifndef O_RDWR 89#ifndef O_RDWR
86#define O_RDWR 2 90#define O_RDWR 2
87#endif 91#endif
@@ -1068,15 +1072,17 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1068 if (!dname_arg || !strchr (dname_arg, '\n')) 1072 if (!dname_arg || !strchr (dname_arg, '\n'))
1069 { /* In orig, child: now exec w/special daemon name. */ 1073 { /* In orig, child: now exec w/special daemon name. */
1070 char fdStr[80]; 1074 char fdStr[80];
1075 int fdStrlen =
1076 snprintf (fdStr, sizeof fdStr,
1077 "--daemon=\n%d,%d\n%s", daemon_pipe[0],
1078 daemon_pipe[1], dname_arg ? dname_arg : "");
1071 1079
1072 if (dname_arg && strlen (dname_arg) > 70) 1080 if (! (0 <= fdStrlen && fdStrlen < sizeof fdStr))
1073 { 1081 {
1074 fprintf (stderr, "daemon: child name too long\n"); 1082 fprintf (stderr, "daemon: child name too long\n");
1075 exit (1); 1083 exit (1);
1076 } 1084 }
1077 1085
1078 sprintf (fdStr, "--daemon=\n%d,%d\n%s", daemon_pipe[0],
1079 daemon_pipe[1], dname_arg ? dname_arg : "");
1080 argv[skip_args] = fdStr; 1086 argv[skip_args] = fdStr;
1081 1087
1082 execv (argv[0], argv); 1088 execv (argv[0], argv);
@@ -2097,6 +2103,10 @@ shut_down_emacs (int sig, int no_x, Lisp_Object stuff)
2097#ifdef HAVE_NS 2103#ifdef HAVE_NS
2098 ns_term_shutdown (sig); 2104 ns_term_shutdown (sig);
2099#endif 2105#endif
2106
2107#ifdef HAVE_LIBXML2
2108 xmlCleanupParser ();
2109#endif
2100} 2110}
2101 2111
2102 2112
diff --git a/src/eval.c b/src/eval.c
index e722b53fb72..f2407cede31 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1951,35 +1951,11 @@ verror (const char *m, va_list ap)
1951 char buf[4000]; 1951 char buf[4000];
1952 ptrdiff_t size = sizeof buf; 1952 ptrdiff_t size = sizeof buf;
1953 ptrdiff_t size_max = STRING_BYTES_BOUND + 1; 1953 ptrdiff_t size_max = STRING_BYTES_BOUND + 1;
1954 char const *m_end = m + strlen (m);
1955 char *buffer = buf; 1954 char *buffer = buf;
1956 ptrdiff_t used; 1955 ptrdiff_t used;
1957 Lisp_Object string; 1956 Lisp_Object string;
1958 1957
1959 while (1) 1958 used = evxprintf (&buffer, &size, buf, size_max, m, ap);
1960 {
1961 va_list ap_copy;
1962 va_copy (ap_copy, ap);
1963 used = doprnt (buffer, size, m, m_end, ap_copy);
1964 va_end (ap_copy);
1965
1966 /* Note: the -1 below is because `doprnt' returns the number of bytes
1967 excluding the terminating null byte, and it always terminates with a
1968 null byte, even when producing a truncated message. */
1969 if (used < size - 1)
1970 break;
1971 if (size <= size_max / 2)
1972 size *= 2;
1973 else if (size < size_max)
1974 size = size_max;
1975 else
1976 break; /* and leave the message truncated */
1977
1978 if (buffer != buf)
1979 xfree (buffer);
1980 buffer = (char *) xmalloc (size);
1981 }
1982
1983 string = make_string (buffer, used); 1959 string = make_string (buffer, used);
1984 if (buffer != buf) 1960 if (buffer != buf)
1985 xfree (buffer); 1961 xfree (buffer);
diff --git a/src/filelock.c b/src/filelock.c
index c28ee7837fa..7235c862ef0 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -341,6 +341,9 @@ lock_file_1 (char *lfname, int force)
341 const char *user_name; 341 const char *user_name;
342 const char *host_name; 342 const char *host_name;
343 char *lock_info_str; 343 char *lock_info_str;
344 ptrdiff_t lock_info_size;
345 int symlink_errno;
346 USE_SAFE_ALLOCA;
344 347
345 /* Call this first because it can GC. */ 348 /* Call this first because it can GC. */
346 boot = get_boot_time (); 349 boot = get_boot_time ();
@@ -353,17 +356,14 @@ lock_file_1 (char *lfname, int force)
353 host_name = SSDATA (Fsystem_name ()); 356 host_name = SSDATA (Fsystem_name ());
354 else 357 else
355 host_name = ""; 358 host_name = "";
356 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) 359 lock_info_size = (strlen (user_name) + strlen (host_name)
357 + 2 * INT_STRLEN_BOUND (printmax_t) 360 + 2 * INT_STRLEN_BOUND (printmax_t)
358 + sizeof "@.:"); 361 + sizeof "@.:");
362 SAFE_ALLOCA (lock_info_str, char *, lock_info_size);
359 pid = getpid (); 363 pid = getpid ();
360 364
361 if (boot) 365 esprintf (lock_info_str, boot ? "%s@%s.%"pMd":%"pMd : "%s@%s.%"pMd,
362 sprintf (lock_info_str, "%s@%s.%"pMd":%"pMd, 366 user_name, host_name, pid, boot);
363 user_name, host_name, pid, boot);
364 else
365 sprintf (lock_info_str, "%s@%s.%"pMd,
366 user_name, host_name, pid);
367 367
368 err = symlink (lock_info_str, lfname); 368 err = symlink (lock_info_str, lfname);
369 if (errno == EEXIST && force) 369 if (errno == EEXIST && force)
@@ -372,6 +372,9 @@ lock_file_1 (char *lfname, int force)
372 err = symlink (lock_info_str, lfname); 372 err = symlink (lock_info_str, lfname);
373 } 373 }
374 374
375 symlink_errno = errno;
376 SAFE_FREE ();
377 errno = symlink_errno;
375 return err == 0; 378 return err == 0;
376} 379}
377 380
@@ -541,9 +544,11 @@ lock_file (Lisp_Object fn)
541{ 544{
542 register Lisp_Object attack, orig_fn, encoded_fn; 545 register Lisp_Object attack, orig_fn, encoded_fn;
543 register char *lfname, *locker; 546 register char *lfname, *locker;
547 ptrdiff_t locker_size;
544 lock_info_type lock_info; 548 lock_info_type lock_info;
545 printmax_t pid; 549 printmax_t pid;
546 struct gcpro gcpro1; 550 struct gcpro gcpro1;
551 USE_SAFE_ALLOCA;
547 552
548 /* Don't do locking while dumping Emacs. 553 /* Don't do locking while dumping Emacs.
549 Uncompressing wtmp files uses call-process, which does not work 554 Uncompressing wtmp files uses call-process, which does not work
@@ -580,15 +585,17 @@ lock_file (Lisp_Object fn)
580 return; 585 return;
581 586
582 /* Else consider breaking the lock */ 587 /* Else consider breaking the lock */
583 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) 588 locker_size = (strlen (lock_info.user) + strlen (lock_info.host)
584 + INT_STRLEN_BOUND (printmax_t) 589 + INT_STRLEN_BOUND (printmax_t)
585 + sizeof "@ (pid )"); 590 + sizeof "@ (pid )");
591 SAFE_ALLOCA (locker, char *, locker_size);
586 pid = lock_info.pid; 592 pid = lock_info.pid;
587 sprintf (locker, "%s@%s (pid %"pMd")", 593 esprintf (locker, "%s@%s (pid %"pMd")",
588 lock_info.user, lock_info.host, pid); 594 lock_info.user, lock_info.host, pid);
589 FREE_LOCK_INFO (lock_info); 595 FREE_LOCK_INFO (lock_info);
590 596
591 attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker)); 597 attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker));
598 SAFE_FREE ();
592 if (!NILP (attack)) 599 if (!NILP (attack))
593 /* User says take the lock */ 600 /* User says take the lock */
594 { 601 {
diff --git a/src/font.c b/src/font.c
index 5f8d22157d6..34cacb37ce4 100644
--- a/src/font.c
+++ b/src/font.c
@@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 22
23#include <config.h> 23#include <config.h>
24#include <float.h>
24#include <stdio.h> 25#include <stdio.h>
25#include <ctype.h> 26#include <ctype.h>
26#include <setjmp.h> 27#include <setjmp.h>
@@ -1180,7 +1181,7 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1180 char *p; 1181 char *p;
1181 const char *f[XLFD_REGISTRY_INDEX + 1]; 1182 const char *f[XLFD_REGISTRY_INDEX + 1];
1182 Lisp_Object val; 1183 Lisp_Object val;
1183 int i, j, len = 0; 1184 int i, j, len;
1184 1185
1185 font_assert (FONTP (font)); 1186 font_assert (FONTP (font));
1186 1187
@@ -1195,9 +1196,9 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1195 if (NILP (val)) 1196 if (NILP (val))
1196 { 1197 {
1197 if (j == XLFD_REGISTRY_INDEX) 1198 if (j == XLFD_REGISTRY_INDEX)
1198 f[j] = "*-*", len += 4; 1199 f[j] = "*-*";
1199 else 1200 else
1200 f[j] = "*", len += 2; 1201 f[j] = "*";
1201 } 1202 }
1202 else 1203 else
1203 { 1204 {
@@ -1207,21 +1208,15 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1207 && ! strchr (SSDATA (val), '-')) 1208 && ! strchr (SSDATA (val), '-'))
1208 { 1209 {
1209 /* Change "jisx0208*" and "jisx0208" to "jisx0208*-*". */ 1210 /* Change "jisx0208*" and "jisx0208" to "jisx0208*-*". */
1210 if (SDATA (val)[SBYTES (val) - 1] == '*') 1211 ptrdiff_t alloc = SBYTES (val) + 4;
1211 { 1212 if (nbytes <= alloc)
1212 f[j] = p = alloca (SBYTES (val) + 3); 1213 return -1;
1213 sprintf (p, "%s-*", SDATA (val)); 1214 f[j] = p = alloca (alloc);
1214 len += SBYTES (val) + 3; 1215 sprintf (p, "%s%s-*", SDATA (val),
1215 } 1216 "*" + (SDATA (val)[SBYTES (val) - 1] == '*'));
1216 else
1217 {
1218 f[j] = p = alloca (SBYTES (val) + 4);
1219 sprintf (p, "%s*-*", SDATA (val));
1220 len += SBYTES (val) + 4;
1221 }
1222 } 1217 }
1223 else 1218 else
1224 f[j] = SSDATA (val), len += SBYTES (val) + 1; 1219 f[j] = SSDATA (val);
1225 } 1220 }
1226 } 1221 }
1227 1222
@@ -1230,11 +1225,11 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1230 { 1225 {
1231 val = font_style_symbolic (font, i, 0); 1226 val = font_style_symbolic (font, i, 0);
1232 if (NILP (val)) 1227 if (NILP (val))
1233 f[j] = "*", len += 2; 1228 f[j] = "*";
1234 else 1229 else
1235 { 1230 {
1236 val = SYMBOL_NAME (val); 1231 val = SYMBOL_NAME (val);
1237 f[j] = SSDATA (val), len += SBYTES (val) + 1; 1232 f[j] = SSDATA (val);
1238 } 1233 }
1239 } 1234 }
1240 1235
@@ -1242,64 +1237,62 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1242 font_assert (NUMBERP (val) || NILP (val)); 1237 font_assert (NUMBERP (val) || NILP (val));
1243 if (INTEGERP (val)) 1238 if (INTEGERP (val))
1244 { 1239 {
1245 i = XINT (val); 1240 EMACS_INT v = XINT (val);
1246 if (i <= 0) 1241 if (v <= 0)
1247 i = pixel_size; 1242 v = pixel_size;
1248 if (i > 0) 1243 if (v > 0)
1249 { 1244 {
1250 f[XLFD_PIXEL_INDEX] = p = alloca (22); 1245 f[XLFD_PIXEL_INDEX] = p =
1251 len += sprintf (p, "%d-*", i) + 1; 1246 alloca (sizeof "-*" + INT_STRLEN_BOUND (EMACS_INT));
1247 sprintf (p, "%"pI"d-*", v);
1252 } 1248 }
1253 else 1249 else
1254 f[XLFD_PIXEL_INDEX] = "*-*", len += 4; 1250 f[XLFD_PIXEL_INDEX] = "*-*";
1255 } 1251 }
1256 else if (FLOATP (val)) 1252 else if (FLOATP (val))
1257 { 1253 {
1258 i = XFLOAT_DATA (val) * 10; 1254 double v = XFLOAT_DATA (val) * 10;
1259 f[XLFD_PIXEL_INDEX] = p = alloca (12); 1255 f[XLFD_PIXEL_INDEX] = p = alloca (sizeof "*-" + 1 + DBL_MAX_10_EXP + 1);
1260 len += sprintf (p, "*-%d", i) + 1; 1256 sprintf (p, "*-%.0f", v);
1261 } 1257 }
1262 else 1258 else
1263 f[XLFD_PIXEL_INDEX] = "*-*", len += 4; 1259 f[XLFD_PIXEL_INDEX] = "*-*";
1264 1260
1265 if (INTEGERP (AREF (font, FONT_DPI_INDEX))) 1261 if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
1266 { 1262 {
1267 i = XINT (AREF (font, FONT_DPI_INDEX)); 1263 EMACS_INT v = XINT (AREF (font, FONT_DPI_INDEX));
1268 f[XLFD_RESX_INDEX] = p = alloca (22); 1264 f[XLFD_RESX_INDEX] = p =
1269 len += sprintf (p, "%d-%d", i, i) + 1; 1265 alloca (sizeof "-" + 2 * INT_STRLEN_BOUND (EMACS_INT));
1266 sprintf (p, "%"pI"d-%"pI"d", v, v);
1270 } 1267 }
1271 else 1268 else
1272 f[XLFD_RESX_INDEX] = "*-*", len += 4; 1269 f[XLFD_RESX_INDEX] = "*-*";
1273 if (INTEGERP (AREF (font, FONT_SPACING_INDEX))) 1270 if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
1274 { 1271 {
1275 int spacing = XINT (AREF (font, FONT_SPACING_INDEX)); 1272 EMACS_INT spacing = XINT (AREF (font, FONT_SPACING_INDEX));
1276 1273
1277 f[XLFD_SPACING_INDEX] = (spacing <= FONT_SPACING_PROPORTIONAL ? "p" 1274 f[XLFD_SPACING_INDEX] = (spacing <= FONT_SPACING_PROPORTIONAL ? "p"
1278 : spacing <= FONT_SPACING_DUAL ? "d" 1275 : spacing <= FONT_SPACING_DUAL ? "d"
1279 : spacing <= FONT_SPACING_MONO ? "m" 1276 : spacing <= FONT_SPACING_MONO ? "m"
1280 : "c"); 1277 : "c");
1281 len += 2;
1282 } 1278 }
1283 else 1279 else
1284 f[XLFD_SPACING_INDEX] = "*", len += 2; 1280 f[XLFD_SPACING_INDEX] = "*";
1285 if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX))) 1281 if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
1286 { 1282 {
1287 f[XLFD_AVGWIDTH_INDEX] = p = alloca (22); 1283 f[XLFD_AVGWIDTH_INDEX] = p = alloca (INT_BUFSIZE_BOUND (EMACS_INT));
1288 len += sprintf (p, "%"pI"d", 1284 sprintf (p, "%"pI"d", XINT (AREF (font, FONT_AVGWIDTH_INDEX)));
1289 XINT (AREF (font, FONT_AVGWIDTH_INDEX))) + 1;
1290 } 1285 }
1291 else 1286 else
1292 f[XLFD_AVGWIDTH_INDEX] = "*", len += 2; 1287 f[XLFD_AVGWIDTH_INDEX] = "*";
1293 len++; /* for terminating '\0'. */ 1288 len = snprintf (name, nbytes, "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
1294 if (len >= nbytes)
1295 return -1;
1296 return sprintf (name, "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
1297 f[XLFD_FOUNDRY_INDEX], f[XLFD_FAMILY_INDEX], 1289 f[XLFD_FOUNDRY_INDEX], f[XLFD_FAMILY_INDEX],
1298 f[XLFD_WEIGHT_INDEX], f[XLFD_SLANT_INDEX], 1290 f[XLFD_WEIGHT_INDEX], f[XLFD_SLANT_INDEX],
1299 f[XLFD_SWIDTH_INDEX], f[XLFD_ADSTYLE_INDEX], 1291 f[XLFD_SWIDTH_INDEX], f[XLFD_ADSTYLE_INDEX],
1300 f[XLFD_PIXEL_INDEX], f[XLFD_RESX_INDEX], 1292 f[XLFD_PIXEL_INDEX], f[XLFD_RESX_INDEX],
1301 f[XLFD_SPACING_INDEX], f[XLFD_AVGWIDTH_INDEX], 1293 f[XLFD_SPACING_INDEX], f[XLFD_AVGWIDTH_INDEX],
1302 f[XLFD_REGISTRY_INDEX]); 1294 f[XLFD_REGISTRY_INDEX]);
1295 return len < nbytes ? len : -1;
1303} 1296}
1304 1297
1305/* Parse NAME (null terminated) and store information in FONT 1298/* Parse NAME (null terminated) and store information in FONT
@@ -1553,23 +1546,19 @@ int
1553font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes) 1546font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
1554{ 1547{
1555 Lisp_Object family, foundry; 1548 Lisp_Object family, foundry;
1556 Lisp_Object tail, val; 1549 Lisp_Object val;
1557 int point_size; 1550 int point_size;
1558 int i; 1551 int i;
1559 ptrdiff_t len = 1;
1560 char *p; 1552 char *p;
1553 char *lim;
1561 Lisp_Object styles[3]; 1554 Lisp_Object styles[3];
1562 const char *style_names[3] = { "weight", "slant", "width" }; 1555 const char *style_names[3] = { "weight", "slant", "width" };
1563 char work[256];
1564 1556
1565 family = AREF (font, FONT_FAMILY_INDEX); 1557 family = AREF (font, FONT_FAMILY_INDEX);
1566 if (! NILP (family)) 1558 if (! NILP (family))
1567 { 1559 {
1568 if (SYMBOLP (family)) 1560 if (SYMBOLP (family))
1569 { 1561 family = SYMBOL_NAME (family);
1570 family = SYMBOL_NAME (family);
1571 len += SBYTES (family);
1572 }
1573 else 1562 else
1574 family = Qnil; 1563 family = Qnil;
1575 } 1564 }
@@ -1580,7 +1569,6 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
1580 if (XINT (val) != 0) 1569 if (XINT (val) != 0)
1581 pixel_size = XINT (val); 1570 pixel_size = XINT (val);
1582 point_size = -1; 1571 point_size = -1;
1583 len += 21; /* for ":pixelsize=NUM" */
1584 } 1572 }
1585 else 1573 else
1586 { 1574 {
@@ -1588,80 +1576,91 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
1588 abort (); 1576 abort ();
1589 pixel_size = -1; 1577 pixel_size = -1;
1590 point_size = (int) XFLOAT_DATA (val); 1578 point_size = (int) XFLOAT_DATA (val);
1591 len += 11; /* for "-NUM" */
1592 } 1579 }
1593 1580
1594 foundry = AREF (font, FONT_FOUNDRY_INDEX); 1581 foundry = AREF (font, FONT_FOUNDRY_INDEX);
1595 if (! NILP (foundry)) 1582 if (! NILP (foundry))
1596 { 1583 {
1597 if (SYMBOLP (foundry)) 1584 if (SYMBOLP (foundry))
1598 { 1585 foundry = SYMBOL_NAME (foundry);
1599 foundry = SYMBOL_NAME (foundry);
1600 len += 9 + SBYTES (foundry); /* ":foundry=NAME" */
1601 }
1602 else 1586 else
1603 foundry = Qnil; 1587 foundry = Qnil;
1604 } 1588 }
1605 1589
1606 for (i = 0; i < 3; i++) 1590 for (i = 0; i < 3; i++)
1607 { 1591 styles[i] = font_style_symbolic (font, FONT_WEIGHT_INDEX + i, 0);
1608 styles[i] = font_style_symbolic (font, FONT_WEIGHT_INDEX + i, 0);
1609 if (! NILP (styles[i]))
1610 len += sprintf (work, ":%s=%s", style_names[i],
1611 SDATA (SYMBOL_NAME (styles[i])));
1612 }
1613
1614 if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
1615 len += sprintf (work, ":dpi=%"pI"d", XINT (AREF (font, FONT_DPI_INDEX)));
1616 if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
1617 len += strlen (":spacing=100");
1618 if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
1619 len += strlen (":scalable=false"); /* or ":scalable=true" */
1620 for (tail = AREF (font, FONT_EXTRA_INDEX); CONSP (tail); tail = XCDR (tail))
1621 {
1622 Lisp_Object key = XCAR (XCAR (tail)), value = XCDR (XCAR (tail));
1623
1624 len += SBYTES (SYMBOL_NAME (key)) + 1; /* for :KEY= */
1625 if (STRINGP (value))
1626 len += SBYTES (value);
1627 else if (INTEGERP (value))
1628 len += sprintf (work, "%"pI"d", XINT (value));
1629 else if (SYMBOLP (value))
1630 len += (NILP (value) ? 5 : 4); /* for "false" or "true" */
1631 }
1632 1592
1633 if (len > nbytes)
1634 return -1;
1635 p = name; 1593 p = name;
1594 lim = name + nbytes;
1636 if (! NILP (family)) 1595 if (! NILP (family))
1637 p += sprintf (p, "%s", SDATA (family)); 1596 {
1597 int len = snprintf (p, lim - p, "%s", SSDATA (family));
1598 if (! (0 <= len && len < lim - p))
1599 return -1;
1600 p += len;
1601 }
1638 if (point_size > 0) 1602 if (point_size > 0)
1639 { 1603 {
1640 if (p == name) 1604 int len = snprintf (p, lim - p, "-%d" + (p == name), point_size);
1641 p += sprintf (p, "%d", point_size); 1605 if (! (0 <= len && len < lim - p))
1642 else 1606 return -1;
1643 p += sprintf (p, "-%d", point_size); 1607 p += len;
1644 } 1608 }
1645 else if (pixel_size > 0) 1609 else if (pixel_size > 0)
1646 p += sprintf (p, ":pixelsize=%d", pixel_size); 1610 {
1611 int len = snprintf (p, lim - p, ":pixelsize=%d", pixel_size);
1612 if (! (0 <= len && len < lim - p))
1613 return -1;
1614 p += len;
1615 }
1647 if (! NILP (AREF (font, FONT_FOUNDRY_INDEX))) 1616 if (! NILP (AREF (font, FONT_FOUNDRY_INDEX)))
1648 p += sprintf (p, ":foundry=%s", 1617 {
1649 SDATA (SYMBOL_NAME (AREF (font, FONT_FOUNDRY_INDEX)))); 1618 int len = snprintf (p, lim - p, ":foundry=%s",
1619 SSDATA (SYMBOL_NAME (AREF (font,
1620 FONT_FOUNDRY_INDEX))));
1621 if (! (0 <= len && len < lim - p))
1622 return -1;
1623 p += len;
1624 }
1650 for (i = 0; i < 3; i++) 1625 for (i = 0; i < 3; i++)
1651 if (! NILP (styles[i])) 1626 if (! NILP (styles[i]))
1652 p += sprintf (p, ":%s=%s", style_names[i], 1627 {
1653 SDATA (SYMBOL_NAME (styles[i]))); 1628 int len = snprintf (p, lim - p, ":%s=%s", style_names[i],
1629 SSDATA (SYMBOL_NAME (styles[i])));
1630 if (! (0 <= len && len < lim - p))
1631 return -1;
1632 p += len;
1633 }
1634
1654 if (INTEGERP (AREF (font, FONT_DPI_INDEX))) 1635 if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
1655 p += sprintf (p, ":dpi=%"pI"d", XINT (AREF (font, FONT_DPI_INDEX))); 1636 {
1637 int len = snprintf (p, lim - p, ":dpi=%"pI"d",
1638 XINT (AREF (font, FONT_DPI_INDEX)));
1639 if (! (0 <= len && len < lim - p))
1640 return -1;
1641 p += len;
1642 }
1643
1656 if (INTEGERP (AREF (font, FONT_SPACING_INDEX))) 1644 if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
1657 p += sprintf (p, ":spacing=%"pI"d", XINT (AREF (font, FONT_SPACING_INDEX))); 1645 {
1646 int len = snprintf (p, lim - p, ":spacing=%"pI"d",
1647 XINT (AREF (font, FONT_SPACING_INDEX)));
1648 if (! (0 <= len && len < lim - p))
1649 return -1;
1650 p += len;
1651 }
1652
1658 if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX))) 1653 if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
1659 { 1654 {
1660 if (XINT (AREF (font, FONT_AVGWIDTH_INDEX)) == 0) 1655 int len = snprintf (p, lim - p,
1661 p += sprintf (p, ":scalable=true"); 1656 (XINT (AREF (font, FONT_AVGWIDTH_INDEX)) == 0
1662 else 1657 ? ":scalable=true"
1663 p += sprintf (p, ":scalable=false"); 1658 : ":scalable=false"));
1659 if (! (0 <= len && len < lim - p))
1660 return -1;
1661 p += len;
1664 } 1662 }
1663
1665 return (p - name); 1664 return (p - name);
1666} 1665}
1667 1666
@@ -1952,12 +1951,12 @@ generate_otf_features (Lisp_Object spec, char *features)
1952 else if (! asterisk) 1951 else if (! asterisk)
1953 { 1952 {
1954 val = SYMBOL_NAME (val); 1953 val = SYMBOL_NAME (val);
1955 p += sprintf (p, "%s", SDATA (val)); 1954 p += esprintf (p, "%s", SDATA (val));
1956 } 1955 }
1957 else 1956 else
1958 { 1957 {
1959 val = SYMBOL_NAME (val); 1958 val = SYMBOL_NAME (val);
1960 p += sprintf (p, "~%s", SDATA (val)); 1959 p += esprintf (p, "~%s", SDATA (val));
1961 } 1960 }
1962 } 1961 }
1963 if (CONSP (spec)) 1962 if (CONSP (spec))
diff --git a/src/fontset.c b/src/fontset.c
index c8ae1e74848..74a25a1ca04 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1700,7 +1700,7 @@ FONT-SPEC is a vector, a cons, or a string. See the documentation of
1700static Lisp_Object auto_fontset_alist; 1700static Lisp_Object auto_fontset_alist;
1701 1701
1702/* Number of automatically created fontsets. */ 1702/* Number of automatically created fontsets. */
1703static int num_auto_fontsets; 1703static printmax_t num_auto_fontsets;
1704 1704
1705/* Retun a fontset synthesized from FONT-OBJECT. This is called from 1705/* Retun a fontset synthesized from FONT-OBJECT. This is called from
1706 x_new_font when FONT-OBJECT is used for the default ASCII font of a 1706 x_new_font when FONT-OBJECT is used for the default ASCII font of a
@@ -1727,9 +1727,9 @@ fontset_from_font (Lisp_Object font_object)
1727 alias = intern ("fontset-startup"); 1727 alias = intern ("fontset-startup");
1728 else 1728 else
1729 { 1729 {
1730 char temp[32]; 1730 char temp[sizeof "fontset-auto" + INT_STRLEN_BOUND (printmax_t)];
1731 1731
1732 sprintf (temp, "fontset-auto%d", num_auto_fontsets - 1); 1732 sprintf (temp, "fontset-auto%"pMd, num_auto_fontsets - 1);
1733 alias = intern (temp); 1733 alias = intern (temp);
1734 } 1734 }
1735 fontset_spec = copy_font_spec (font_spec); 1735 fontset_spec = copy_font_spec (font_spec);
diff --git a/src/frame.c b/src/frame.c
index 711109a70c6..66b857a73e9 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -497,7 +497,7 @@ make_minibuffer_frame (void)
497 497
498/* Construct a frame that refers to a terminal. */ 498/* Construct a frame that refers to a terminal. */
499 499
500static int tty_frame_count; 500static printmax_t tty_frame_count;
501 501
502struct frame * 502struct frame *
503make_initial_frame (void) 503make_initial_frame (void)
@@ -551,7 +551,7 @@ make_terminal_frame (struct terminal *terminal)
551{ 551{
552 register struct frame *f; 552 register struct frame *f;
553 Lisp_Object frame; 553 Lisp_Object frame;
554 char name[20]; 554 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
555 555
556 if (!terminal->name) 556 if (!terminal->name)
557 error ("Terminal is not live, can't create new frames on it"); 557 error ("Terminal is not live, can't create new frames on it");
@@ -562,7 +562,7 @@ make_terminal_frame (struct terminal *terminal)
562 Vframe_list = Fcons (frame, Vframe_list); 562 Vframe_list = Fcons (frame, Vframe_list);
563 563
564 tty_frame_count++; 564 tty_frame_count++;
565 sprintf (name, "F%d", tty_frame_count); 565 sprintf (name, "F%"pMd, tty_frame_count);
566 f->name = build_string (name); 566 f->name = build_string (name);
567 567
568 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ 568 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
@@ -2074,7 +2074,7 @@ set_term_frame_name (struct frame *f, Lisp_Object name)
2074 /* If NAME is nil, set the name to F<num>. */ 2074 /* If NAME is nil, set the name to F<num>. */
2075 if (NILP (name)) 2075 if (NILP (name))
2076 { 2076 {
2077 char namebuf[20]; 2077 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2078 2078
2079 /* Check for no change needed in this very common case 2079 /* Check for no change needed in this very common case
2080 before we do any consing. */ 2080 before we do any consing. */
@@ -2083,7 +2083,7 @@ set_term_frame_name (struct frame *f, Lisp_Object name)
2083 return; 2083 return;
2084 2084
2085 tty_frame_count++; 2085 tty_frame_count++;
2086 sprintf (namebuf, "F%d", tty_frame_count); 2086 sprintf (namebuf, "F%"pMd, tty_frame_count);
2087 name = build_string (namebuf); 2087 name = build_string (namebuf);
2088 } 2088 }
2089 else 2089 else
@@ -3065,6 +3065,7 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3065{ 3065{
3066 char buf[16]; 3066 char buf[16];
3067 Lisp_Object tem; 3067 Lisp_Object tem;
3068 unsigned long w;
3068 3069
3069 /* Represent negative positions (off the top or left screen edge) 3070 /* Represent negative positions (off the top or left screen edge)
3070 in a way that Fmodify_frame_parameters will understand correctly. */ 3071 in a way that Fmodify_frame_parameters will understand correctly. */
@@ -3097,7 +3098,8 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3097 for non-toolkit scroll bar. 3098 for non-toolkit scroll bar.
3098 ruler-mode.el depends on this. */ 3099 ruler-mode.el depends on this. */
3099 : Qnil)); 3100 : Qnil));
3100 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f)); 3101 w = FRAME_X_WINDOW (f);
3102 sprintf (buf, "%lu", w);
3101 store_in_alist (alistptr, Qwindow_id, 3103 store_in_alist (alistptr, Qwindow_id,
3102 build_string (buf)); 3104 build_string (buf));
3103#ifdef HAVE_X_WINDOWS 3105#ifdef HAVE_X_WINDOWS
@@ -3105,7 +3107,10 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3105 /* Tooltip frame may not have this widget. */ 3107 /* Tooltip frame may not have this widget. */
3106 if (FRAME_X_OUTPUT (f)->widget) 3108 if (FRAME_X_OUTPUT (f)->widget)
3107#endif 3109#endif
3108 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f)); 3110 {
3111 w = FRAME_OUTER_WINDOW (f);
3112 sprintf (buf, "%lu", w);
3113 }
3109 store_in_alist (alistptr, Qouter_window_id, 3114 store_in_alist (alistptr, Qouter_window_id,
3110 build_string (buf)); 3115 build_string (buf));
3111#endif 3116#endif
@@ -3576,13 +3581,13 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3576void 3581void
3577validate_x_resource_name (void) 3582validate_x_resource_name (void)
3578{ 3583{
3579 int len = 0; 3584 ptrdiff_t len = 0;
3580 /* Number of valid characters in the resource name. */ 3585 /* Number of valid characters in the resource name. */
3581 int good_count = 0; 3586 ptrdiff_t good_count = 0;
3582 /* Number of invalid characters in the resource name. */ 3587 /* Number of invalid characters in the resource name. */
3583 int bad_count = 0; 3588 ptrdiff_t bad_count = 0;
3584 Lisp_Object new; 3589 Lisp_Object new;
3585 int i; 3590 ptrdiff_t i;
3586 3591
3587 if (!STRINGP (Vx_resource_class)) 3592 if (!STRINGP (Vx_resource_class))
3588 Vx_resource_class = build_string (EMACS_CLASS); 3593 Vx_resource_class = build_string (EMACS_CLASS);
@@ -3615,8 +3620,9 @@ validate_x_resource_name (void)
3615 if (bad_count == 0) 3620 if (bad_count == 0)
3616 return; 3621 return;
3617 3622
3618 /* If name is entirely invalid, or nearly so, use `emacs'. */ 3623 /* If name is entirely invalid, or nearly so, or is so implausibly
3619 if (good_count < 2) 3624 large that alloca might not work, use `emacs'. */
3625 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3620 { 3626 {
3621 Vx_resource_name = build_string ("emacs"); 3627 Vx_resource_name = build_string ("emacs");
3622 return; 3628 return;
@@ -3745,20 +3751,24 @@ x_get_resource_string (const char *attribute, const char *class)
3745{ 3751{
3746 char *name_key; 3752 char *name_key;
3747 char *class_key; 3753 char *class_key;
3754 char *result;
3748 struct frame *sf = SELECTED_FRAME (); 3755 struct frame *sf = SELECTED_FRAME ();
3756 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3757 USE_SAFE_ALLOCA;
3749 3758
3750 /* Allocate space for the components, the dots which separate them, 3759 /* Allocate space for the components, the dots which separate them,
3751 and the final '\0'. */ 3760 and the final '\0'. */
3752 name_key = (char *) alloca (SBYTES (Vinvocation_name) 3761 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3753 + strlen (attribute) + 2);
3754 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1) 3762 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3755 + strlen (class) + 2); 3763 + strlen (class) + 2);
3756 3764
3757 sprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute); 3765 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3758 sprintf (class_key, "%s.%s", EMACS_CLASS, class); 3766 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3759 3767
3760 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb, 3768 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3761 name_key, class_key); 3769 name_key, class_key);
3770 SAFE_FREE ();
3771 return result;
3762} 3772}
3763#endif 3773#endif
3764 3774
diff --git a/src/gtkutil.c b/src/gtkutil.c
index c39119c8151..c154797735e 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20#include <config.h> 20#include <config.h>
21 21
22#ifdef USE_GTK 22#ifdef USE_GTK
23#include <float.h>
23#include <signal.h> 24#include <signal.h>
24#include <stdio.h> 25#include <stdio.h>
25#include <setjmp.h> 26#include <setjmp.h>
@@ -567,7 +568,7 @@ xg_check_special_colors (struct frame *f,
567 GtkStyleContext *gsty 568 GtkStyleContext *gsty
568 = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f)); 569 = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f));
569 GdkRGBA col; 570 GdkRGBA col;
570 char buf[64]; 571 char buf[sizeof "rgbi://" + 3 * (DBL_MAX_10_EXP + sizeof "-1.000000" - 1)];
571 int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED; 572 int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED;
572 if (get_fg) 573 if (get_fg)
573 gtk_style_context_get_color (gsty, state, &col); 574 gtk_style_context_get_color (gsty, state, &col);
@@ -797,7 +798,7 @@ xg_set_geometry (FRAME_PTR f)
797 int xneg = f->size_hint_flags & XNegative; 798 int xneg = f->size_hint_flags & XNegative;
798 int top = f->top_pos; 799 int top = f->top_pos;
799 int yneg = f->size_hint_flags & YNegative; 800 int yneg = f->size_hint_flags & YNegative;
800 char geom_str[32]; 801 char geom_str[sizeof "=x--" + 4 * INT_STRLEN_BOUND (int)];
801 802
802 if (xneg) 803 if (xneg)
803 left = -left; 804 left = -left;
diff --git a/src/indent.c b/src/indent.c
index 313315e9081..6e602d28f60 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -56,7 +56,7 @@ EMACS_INT last_known_column_point;
56static int last_known_column_modified; 56static int last_known_column_modified;
57 57
58static EMACS_INT current_column_1 (void); 58static EMACS_INT current_column_1 (void);
59static EMACS_INT position_indentation (int); 59static EMACS_INT position_indentation (ptrdiff_t);
60 60
61/* Cache of beginning of line found by the last call of 61/* Cache of beginning of line found by the last call of
62 current_column. */ 62 current_column. */
@@ -855,7 +855,7 @@ following any initial whitespace. */)
855} 855}
856 856
857static EMACS_INT 857static EMACS_INT
858position_indentation (register int pos_byte) 858position_indentation (ptrdiff_t pos_byte)
859{ 859{
860 register EMACS_INT column = 0; 860 register EMACS_INT column = 0;
861 int tab_width = SANE_TAB_WIDTH (current_buffer); 861 int tab_width = SANE_TAB_WIDTH (current_buffer);
@@ -2063,7 +2063,7 @@ whether or not it is currently displayed in some window. */)
2063 /* Do this even if LINES is 0, so that we move back to the 2063 /* Do this even if LINES is 0, so that we move back to the
2064 beginning of the current line as we ought. */ 2064 beginning of the current line as we ought. */
2065 if (XINT (lines) == 0 || IT_CHARPOS (it) > 0) 2065 if (XINT (lines) == 0 || IT_CHARPOS (it) > 0)
2066 move_it_by_lines (&it, XINT (lines)); 2066 move_it_by_lines (&it, max (INT_MIN, XINT (lines)));
2067 } 2067 }
2068 else 2068 else
2069 { 2069 {
@@ -2083,7 +2083,7 @@ whether or not it is currently displayed in some window. */)
2083 && it.c == '\n')) 2083 && it.c == '\n'))
2084 move_it_by_lines (&it, -1); 2084 move_it_by_lines (&it, -1);
2085 it.vpos = 0; 2085 it.vpos = 0;
2086 move_it_by_lines (&it, XINT (lines)); 2086 move_it_by_lines (&it, min (INT_MAX, XINT (lines)));
2087 } 2087 }
2088 else 2088 else
2089 { 2089 {
@@ -2099,12 +2099,12 @@ whether or not it is currently displayed in some window. */)
2099 move_it_by_lines (&it, 1); 2099 move_it_by_lines (&it, 1);
2100 } 2100 }
2101 if (XINT (lines) > 1) 2101 if (XINT (lines) > 1)
2102 move_it_by_lines (&it, XINT (lines) - 1); 2102 move_it_by_lines (&it, min (INT_MAX, XINT (lines) - 1));
2103 } 2103 }
2104 else 2104 else
2105 { 2105 {
2106 it.vpos = 0; 2106 it.vpos = 0;
2107 move_it_by_lines (&it, XINT (lines)); 2107 move_it_by_lines (&it, min (INT_MAX, XINT (lines)));
2108 } 2108 }
2109 } 2109 }
2110 } 2110 }
diff --git a/src/keyboard.c b/src/keyboard.c
index ab93e0ccd24..51eac369e7c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -196,7 +196,7 @@ int immediate_quit;
196int quit_char; 196int quit_char;
197 197
198/* Current depth in recursive edits. */ 198/* Current depth in recursive edits. */
199int command_loop_level; 199EMACS_INT command_loop_level;
200 200
201/* If not Qnil, this is a switch-frame event which we decided to put 201/* If not Qnil, this is a switch-frame event which we decided to put
202 off until the end of a key sequence. This should be read as the 202 off until the end of a key sequence. This should be read as the
@@ -998,7 +998,8 @@ static Lisp_Object
998cmd_error (Lisp_Object data) 998cmd_error (Lisp_Object data)
999{ 999{
1000 Lisp_Object old_level, old_length; 1000 Lisp_Object old_level, old_length;
1001 char macroerror[50]; 1001 char macroerror[sizeof "After..kbd macro iterations: "
1002 + INT_STRLEN_BOUND (EMACS_INT)];
1002 1003
1003#ifdef HAVE_WINDOW_SYSTEM 1004#ifdef HAVE_WINDOW_SYSTEM
1004 if (display_hourglass_p) 1005 if (display_hourglass_p)
@@ -1010,7 +1011,7 @@ cmd_error (Lisp_Object data)
1010 if (executing_kbd_macro_iterations == 1) 1011 if (executing_kbd_macro_iterations == 1)
1011 sprintf (macroerror, "After 1 kbd macro iteration: "); 1012 sprintf (macroerror, "After 1 kbd macro iteration: ");
1012 else 1013 else
1013 sprintf (macroerror, "After %d kbd macro iterations: ", 1014 sprintf (macroerror, "After %"pI"d kbd macro iterations: ",
1014 executing_kbd_macro_iterations); 1015 executing_kbd_macro_iterations);
1015 } 1016 }
1016 else 1017 else
@@ -6463,11 +6464,15 @@ modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object s
6463 value = Fcdr_safe (Fassq (symbol_int, name_alist_or_stem)); 6464 value = Fcdr_safe (Fassq (symbol_int, name_alist_or_stem));
6464 else if (STRINGP (name_alist_or_stem)) 6465 else if (STRINGP (name_alist_or_stem))
6465 { 6466 {
6466 int len = SBYTES (name_alist_or_stem); 6467 char *buf;
6467 char *buf = (char *) alloca (len + 50); 6468 ptrdiff_t len = (SBYTES (name_alist_or_stem)
6468 sprintf (buf, "%s-%"pI"d", SDATA (name_alist_or_stem), 6469 + sizeof "-" + INT_STRLEN_BOUND (EMACS_INT));
6469 XINT (symbol_int) + 1); 6470 USE_SAFE_ALLOCA;
6471 SAFE_ALLOCA (buf, char *, len);
6472 esprintf (buf, "%s-%"pI"d", SDATA (name_alist_or_stem),
6473 XINT (symbol_int) + 1);
6470 value = intern (buf); 6474 value = intern (buf);
6475 SAFE_FREE ();
6471 } 6476 }
6472 else if (name_table != 0 && name_table[symbol_num]) 6477 else if (name_table != 0 && name_table[symbol_num])
6473 value = intern (name_table[symbol_num]); 6478 value = intern (name_table[symbol_num]);
@@ -6483,7 +6488,7 @@ modify_event_symbol (EMACS_INT symbol_num, unsigned int modifiers, Lisp_Object s
6483 6488
6484 if (NILP (value)) 6489 if (NILP (value))
6485 { 6490 {
6486 char buf[20]; 6491 char buf[sizeof "key-" + INT_STRLEN_BOUND (EMACS_INT)];
6487 sprintf (buf, "key-%"pI"d", symbol_num); 6492 sprintf (buf, "key-%"pI"d", symbol_num);
6488 value = intern (buf); 6493 value = intern (buf);
6489 } 6494 }
@@ -10382,19 +10387,21 @@ give to the command you invoke, if it asks for an argument. */)
10382 char *newmessage; 10387 char *newmessage;
10383 int message_p = push_message (); 10388 int message_p = push_message ();
10384 int count = SPECPDL_INDEX (); 10389 int count = SPECPDL_INDEX ();
10390 ptrdiff_t newmessage_len, newmessage_alloc;
10391 USE_SAFE_ALLOCA;
10385 10392
10386 record_unwind_protect (pop_message_unwind, Qnil); 10393 record_unwind_protect (pop_message_unwind, Qnil);
10387 binding = Fkey_description (bindings, Qnil); 10394 binding = Fkey_description (bindings, Qnil);
10388 10395 newmessage_alloc =
10389 newmessage 10396 (sizeof "You can run the command `' with "
10390 = (char *) alloca (SCHARS (SYMBOL_NAME (function)) 10397 + SBYTES (SYMBOL_NAME (function)) + SBYTES (binding));
10391 + SBYTES (binding) 10398 SAFE_ALLOCA (newmessage, char *, newmessage_alloc);
10392 + 100); 10399 newmessage_len =
10393 sprintf (newmessage, "You can run the command `%s' with %s", 10400 esprintf (newmessage, "You can run the command `%s' with %s",
10394 SDATA (SYMBOL_NAME (function)), 10401 SDATA (SYMBOL_NAME (function)),
10395 SDATA (binding)); 10402 SDATA (binding));
10396 message2 (newmessage, 10403 message2 (newmessage,
10397 strlen (newmessage), 10404 newmessage_len,
10398 STRING_MULTIBYTE (binding)); 10405 STRING_MULTIBYTE (binding));
10399 if (NUMBERP (Vsuggest_key_bindings)) 10406 if (NUMBERP (Vsuggest_key_bindings))
10400 waited = sit_for (Vsuggest_key_bindings, 0, 2); 10407 waited = sit_for (Vsuggest_key_bindings, 0, 2);
@@ -10404,6 +10411,7 @@ give to the command you invoke, if it asks for an argument. */)
10404 if (!NILP (waited) && message_p) 10411 if (!NILP (waited) && message_p)
10405 restore_message (); 10412 restore_message ();
10406 10413
10414 SAFE_FREE ();
10407 unbind_to (count, Qnil); 10415 unbind_to (count, Qnil);
10408 } 10416 }
10409 } 10417 }
@@ -10633,7 +10641,9 @@ DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0,
10633 (void) 10641 (void)
10634{ 10642{
10635 Lisp_Object temp; 10643 Lisp_Object temp;
10636 XSETFASTINT (temp, command_loop_level + minibuf_level); 10644 /* Wrap around reliably on integer overflow. */
10645 EMACS_INT sum = (command_loop_level & INTMASK) + (minibuf_level & INTMASK);
10646 XSETINT (temp, sum);
10637 return temp; 10647 return temp;
10638} 10648}
10639 10649
diff --git a/src/keymap.c b/src/keymap.c
index 32b531daac4..4485080db21 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2143,12 +2143,12 @@ spaces are put between sequence elements, etc. */)
2143 2143
2144 2144
2145char * 2145char *
2146push_key_description (register unsigned int c, register char *p, int force_multibyte) 2146push_key_description (EMACS_INT ch, char *p, int force_multibyte)
2147{ 2147{
2148 unsigned c2; 2148 int c, c2;
2149 2149
2150 /* Clear all the meaningless bits above the meta bit. */ 2150 /* Clear all the meaningless bits above the meta bit. */
2151 c &= meta_modifier | ~ - meta_modifier; 2151 c = ch & (meta_modifier | ~ - meta_modifier);
2152 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier 2152 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier
2153 | meta_modifier | shift_modifier | super_modifier); 2153 | meta_modifier | shift_modifier | super_modifier);
2154 2154
@@ -2283,10 +2283,15 @@ around function keys and event symbols. */)
2283 { 2283 {
2284 if (NILP (no_angles)) 2284 if (NILP (no_angles))
2285 { 2285 {
2286 char *buffer 2286 char *buffer;
2287 = (char *) alloca (SBYTES (SYMBOL_NAME (key)) + 5); 2287 Lisp_Object result;
2288 sprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key))); 2288 USE_SAFE_ALLOCA;
2289 return build_string (buffer); 2289 SAFE_ALLOCA (buffer, char *,
2290 sizeof "<>" + SBYTES (SYMBOL_NAME (key)));
2291 esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
2292 result = build_string (buffer);
2293 SAFE_FREE ();
2294 return result;
2290 } 2295 }
2291 else 2296 else
2292 return Fsymbol_name (key); 2297 return Fsymbol_name (key);
diff --git a/src/lisp.h b/src/lisp.h
index 99555118047..5c84bb8e06e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2895,6 +2895,14 @@ extern void syms_of_print (void);
2895/* Defined in doprnt.c */ 2895/* Defined in doprnt.c */
2896extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *, 2896extern ptrdiff_t doprnt (char *, ptrdiff_t, const char *, const char *,
2897 va_list); 2897 va_list);
2898extern ptrdiff_t esprintf (char *, char const *, ...)
2899 ATTRIBUTE_FORMAT_PRINTF (2, 3);
2900extern ptrdiff_t exprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2901 char const *, ...)
2902 ATTRIBUTE_FORMAT_PRINTF (5, 6);
2903extern ptrdiff_t evxprintf (char **, ptrdiff_t *, char const *, ptrdiff_t,
2904 char const *, va_list)
2905 ATTRIBUTE_FORMAT_PRINTF (5, 0);
2898 2906
2899/* Defined in lread.c. */ 2907/* Defined in lread.c. */
2900extern Lisp_Object Qvariable_documentation, Qstandard_input; 2908extern Lisp_Object Qvariable_documentation, Qstandard_input;
@@ -3186,7 +3194,7 @@ EXFUN (Fread_minibuffer, 2);
3186EXFUN (Feval_minibuffer, 2); 3194EXFUN (Feval_minibuffer, 2);
3187EXFUN (Fread_string, 5); 3195EXFUN (Fread_string, 5);
3188EXFUN (Fassoc_string, 3); 3196EXFUN (Fassoc_string, 3);
3189extern Lisp_Object get_minibuffer (int); 3197extern Lisp_Object get_minibuffer (EMACS_INT);
3190extern void init_minibuf_once (void); 3198extern void init_minibuf_once (void);
3191extern void syms_of_minibuf (void); 3199extern void syms_of_minibuf (void);
3192 3200
@@ -3250,7 +3258,7 @@ extern void force_auto_save_soon (void);
3250extern void init_keyboard (void); 3258extern void init_keyboard (void);
3251extern void syms_of_keyboard (void); 3259extern void syms_of_keyboard (void);
3252extern void keys_of_keyboard (void); 3260extern void keys_of_keyboard (void);
3253extern char *push_key_description (unsigned int, char *, int); 3261extern char *push_key_description (EMACS_INT, char *, int);
3254 3262
3255 3263
3256/* Defined in indent.c */ 3264/* Defined in indent.c */
diff --git a/src/lread.c b/src/lread.c
index d24da729df6..ec65e881b0e 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -4295,14 +4295,20 @@ init_lread (void)
4295void 4295void
4296dir_warning (const char *format, Lisp_Object dirname) 4296dir_warning (const char *format, Lisp_Object dirname)
4297{ 4297{
4298 char *buffer
4299 = (char *) alloca (SCHARS (dirname) + strlen (format) + 5);
4300
4301 fprintf (stderr, format, SDATA (dirname)); 4298 fprintf (stderr, format, SDATA (dirname));
4302 sprintf (buffer, format, SDATA (dirname)); 4299
4303 /* Don't log the warning before we've initialized!! */ 4300 /* Don't log the warning before we've initialized!! */
4304 if (initialized) 4301 if (initialized)
4305 message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname)); 4302 {
4303 char *buffer;
4304 ptrdiff_t message_len;
4305 USE_SAFE_ALLOCA;
4306 SAFE_ALLOCA (buffer, char *,
4307 SBYTES (dirname) + strlen (format) - (sizeof "%s" - 1) + 1);
4308 message_len = esprintf (buffer, format, SDATA (dirname));
4309 message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname));
4310 SAFE_FREE ();
4311 }
4306} 4312}
4307 4313
4308void 4314void
diff --git a/src/macros.c b/src/macros.c
index f6cd3a3ccad..4ecf49834a1 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -35,7 +35,7 @@ static Lisp_Object Qkbd_macro_termination_hook;
35 This is not bound at each level, 35 This is not bound at each level,
36 so after an error, it describes the innermost interrupted macro. */ 36 so after an error, it describes the innermost interrupted macro. */
37 37
38int executing_kbd_macro_iterations; 38EMACS_INT executing_kbd_macro_iterations;
39 39
40/* This is the macro that was executing. 40/* This is the macro that was executing.
41 This is not bound at each level, 41 This is not bound at each level,
@@ -175,11 +175,11 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
175 175
176 if (XFASTINT (repeat) == 0) 176 if (XFASTINT (repeat) == 0)
177 Fexecute_kbd_macro (KVAR (current_kboard, Vlast_kbd_macro), repeat, loopfunc); 177 Fexecute_kbd_macro (KVAR (current_kboard, Vlast_kbd_macro), repeat, loopfunc);
178 else 178 else if (XINT (repeat) > 1)
179 { 179 {
180 XSETINT (repeat, XINT (repeat)-1); 180 XSETINT (repeat, XINT (repeat)-1);
181 if (XINT (repeat) > 0) 181 Fexecute_kbd_macro (KVAR (current_kboard, Vlast_kbd_macro),
182 Fexecute_kbd_macro (KVAR (current_kboard, Vlast_kbd_macro), repeat, loopfunc); 182 repeat, loopfunc);
183 } 183 }
184 return Qnil; 184 return Qnil;
185} 185}
@@ -302,9 +302,9 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
302 Lisp_Object final; 302 Lisp_Object final;
303 Lisp_Object tem; 303 Lisp_Object tem;
304 int pdlcount = SPECPDL_INDEX (); 304 int pdlcount = SPECPDL_INDEX ();
305 int repeat = 1; 305 EMACS_INT repeat = 1;
306 struct gcpro gcpro1, gcpro2; 306 struct gcpro gcpro1, gcpro2;
307 int success_count = 0; 307 EMACS_INT success_count = 0;
308 308
309 executing_kbd_macro_iterations = 0; 309 executing_kbd_macro_iterations = 0;
310 310
diff --git a/src/macros.h b/src/macros.h
index 32a97e457e8..7a5d532fbb7 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -22,7 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 This is not bound at each level, 22 This is not bound at each level,
23 so after an error, it describes the innermost interrupted macro. */ 23 so after an error, it describes the innermost interrupted macro. */
24 24
25extern int executing_kbd_macro_iterations; 25extern EMACS_INT executing_kbd_macro_iterations;
26 26
27/* This is the macro that was executing. 27/* This is the macro that was executing.
28 This is not bound at each level, 28 This is not bound at each level,
@@ -42,4 +42,3 @@ extern void finalize_kbd_macro_chars (void);
42/* Store a character into kbd macro being defined */ 42/* Store a character into kbd macro being defined */
43 43
44extern void store_kbd_macro_char (Lisp_Object); 44extern void store_kbd_macro_char (Lisp_Object);
45
diff --git a/src/minibuf.c b/src/minibuf.c
index eb564a10ec6..ad8f3ed8b86 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -49,7 +49,7 @@ static Lisp_Object minibuf_save_list;
49 49
50/* Depth in minibuffer invocations. */ 50/* Depth in minibuffer invocations. */
51 51
52int minibuf_level; 52EMACS_INT minibuf_level;
53 53
54/* The maximum length of a minibuffer history. */ 54/* The maximum length of a minibuffer history. */
55 55
@@ -772,10 +772,10 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
772 used for nonrecursive minibuffer invocations. */ 772 used for nonrecursive minibuffer invocations. */
773 773
774Lisp_Object 774Lisp_Object
775get_minibuffer (int depth) 775get_minibuffer (EMACS_INT depth)
776{ 776{
777 Lisp_Object tail, num, buf; 777 Lisp_Object tail, num, buf;
778 char name[24]; 778 char name[sizeof " *Minibuf-*" + INT_STRLEN_BOUND (EMACS_INT)];
779 779
780 XSETFASTINT (num, depth); 780 XSETFASTINT (num, depth);
781 tail = Fnthcdr (num, Vminibuffer_list); 781 tail = Fnthcdr (num, Vminibuffer_list);
@@ -787,7 +787,7 @@ get_minibuffer (int depth)
787 buf = Fcar (tail); 787 buf = Fcar (tail);
788 if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name))) 788 if (NILP (buf) || NILP (BVAR (XBUFFER (buf), name)))
789 { 789 {
790 sprintf (name, " *Minibuf-%d*", depth); 790 sprintf (name, " *Minibuf-%"pI"d*", depth);
791 buf = Fget_buffer_create (build_string (name)); 791 buf = Fget_buffer_create (build_string (name));
792 792
793 /* Although the buffer's name starts with a space, undo should be 793 /* Although the buffer's name starts with a space, undo should be
diff --git a/src/nsterm.m b/src/nsterm.m
index 4c9574c35ba..827404a2974 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -5316,7 +5316,7 @@ ns_term_shutdown (int sig)
5316 strcpy (old_title, t); 5316 strcpy (old_title, t);
5317 } 5317 }
5318 size_title = xmalloc (strlen (old_title) + 40); 5318 size_title = xmalloc (strlen (old_title) + 40);
5319 sprintf (size_title, "%s — (%d x %d)", old_title, cols, rows); 5319 esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows);
5320 [window setTitle: [NSString stringWithUTF8String: size_title]]; 5320 [window setTitle: [NSString stringWithUTF8String: size_title]];
5321 [window display]; 5321 [window display];
5322 xfree (size_title); 5322 xfree (size_title);
diff --git a/src/print.c b/src/print.c
index 35f89860843..d67149a40ab 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1016,12 +1016,15 @@ float_to_string (char *buf, double data)
1016 { 1016 {
1017 width = 0; 1017 width = 0;
1018 do 1018 do
1019 width = (width * 10) + (*cp++ - '0'); 1019 {
1020 width = (width * 10) + (*cp++ - '0');
1021 if (DBL_DIG < width)
1022 goto lose;
1023 }
1020 while (*cp >= '0' && *cp <= '9'); 1024 while (*cp >= '0' && *cp <= '9');
1021 1025
1022 /* A precision of zero is valid only for %f. */ 1026 /* A precision of zero is valid only for %f. */
1023 if (width > DBL_DIG 1027 if (width == 0 && *cp != 'f')
1024 || (width == 0 && *cp != 'f'))
1025 goto lose; 1028 goto lose;
1026 } 1029 }
1027 1030
@@ -1314,7 +1317,9 @@ print_prune_string_charset (Lisp_Object string)
1314static void 1317static void
1315print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) 1318print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1316{ 1319{
1317 char buf[40]; 1320 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
1321 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t),
1322 40))];
1318 1323
1319 QUIT; 1324 QUIT;
1320 1325
@@ -1614,8 +1619,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1614 PRINTCHAR ('('); 1619 PRINTCHAR ('(');
1615 1620
1616 { 1621 {
1617 EMACS_INT print_length; 1622 printmax_t i, print_length;
1618 int i;
1619 Lisp_Object halftail = obj; 1623 Lisp_Object halftail = obj;
1620 1624
1621 /* Negative values of print-length are invalid in CL. 1625 /* Negative values of print-length are invalid in CL.
@@ -1623,7 +1627,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1623 if (NATNUMP (Vprint_length)) 1627 if (NATNUMP (Vprint_length))
1624 print_length = XFASTINT (Vprint_length); 1628 print_length = XFASTINT (Vprint_length);
1625 else 1629 else
1626 print_length = 0; 1630 print_length = TYPE_MAXIMUM (printmax_t);
1627 1631
1628 i = 0; 1632 i = 0;
1629 while (CONSP (obj)) 1633 while (CONSP (obj))
@@ -1634,7 +1638,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1634 /* Simple but imcomplete way. */ 1638 /* Simple but imcomplete way. */
1635 if (i != 0 && EQ (obj, halftail)) 1639 if (i != 0 && EQ (obj, halftail))
1636 { 1640 {
1637 sprintf (buf, " . #%d", i / 2); 1641 sprintf (buf, " . #%"pMd, i / 2);
1638 strout (buf, -1, -1, printcharfun); 1642 strout (buf, -1, -1, printcharfun);
1639 goto end_of_list; 1643 goto end_of_list;
1640 } 1644 }
@@ -1654,15 +1658,16 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1654 } 1658 }
1655 } 1659 }
1656 1660
1657 if (i++) 1661 if (i)
1658 PRINTCHAR (' '); 1662 PRINTCHAR (' ');
1659 1663
1660 if (print_length && i > print_length) 1664 if (print_length <= i)
1661 { 1665 {
1662 strout ("...", 3, 3, printcharfun); 1666 strout ("...", 3, 3, printcharfun);
1663 goto end_of_list; 1667 goto end_of_list;
1664 } 1668 }
1665 1669
1670 i++;
1666 print_object (XCAR (obj), printcharfun, escapeflag); 1671 print_object (XCAR (obj), printcharfun, escapeflag);
1667 1672
1668 obj = XCDR (obj); 1673 obj = XCDR (obj);
@@ -1697,7 +1702,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1697 } 1702 }
1698 else if (BOOL_VECTOR_P (obj)) 1703 else if (BOOL_VECTOR_P (obj))
1699 { 1704 {
1700 register int i; 1705 ptrdiff_t i;
1701 register unsigned char c; 1706 register unsigned char c;
1702 struct gcpro gcpro1; 1707 struct gcpro gcpro1;
1703 EMACS_INT size_in_chars 1708 EMACS_INT size_in_chars
@@ -1798,19 +1803,17 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1798 PRINTCHAR (' '); 1803 PRINTCHAR (' ');
1799 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun); 1804 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1800 PRINTCHAR (' '); 1805 PRINTCHAR (' ');
1801 sprintf (buf, "%ld/%ld", (long) h->count, 1806 sprintf (buf, "%"pI"d/%"pI"d", h->count, ASIZE (h->next));
1802 (long) ASIZE (h->next));
1803 strout (buf, -1, -1, printcharfun); 1807 strout (buf, -1, -1, printcharfun);
1804 } 1808 }
1805 sprintf (buf, " 0x%lx", (unsigned long) h); 1809 sprintf (buf, " %p", h);
1806 strout (buf, -1, -1, printcharfun); 1810 strout (buf, -1, -1, printcharfun);
1807 PRINTCHAR ('>'); 1811 PRINTCHAR ('>');
1808#endif 1812#endif
1809 /* Implement a readable output, e.g.: 1813 /* Implement a readable output, e.g.:
1810 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ 1814 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1811 /* Always print the size. */ 1815 /* Always print the size. */
1812 sprintf (buf, "#s(hash-table size %ld", 1816 sprintf (buf, "#s(hash-table size %"pI"d", ASIZE (h->next));
1813 (long) ASIZE (h->next));
1814 strout (buf, -1, -1, printcharfun); 1817 strout (buf, -1, -1, printcharfun);
1815 1818
1816 if (!NILP (h->test)) 1819 if (!NILP (h->test))
@@ -2038,7 +2041,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2038 if (MISCP (obj)) 2041 if (MISCP (obj))
2039 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2042 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2040 else if (VECTORLIKEP (obj)) 2043 else if (VECTORLIKEP (obj))
2041 sprintf (buf, "(PVEC 0x%08lx)", (unsigned long) ASIZE (obj)); 2044 sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj));
2042 else 2045 else
2043 sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2046 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2044 strout (buf, -1, -1, printcharfun); 2047 strout (buf, -1, -1, printcharfun);
diff --git a/src/process.c b/src/process.c
index a8088322147..058ad5f871f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -616,8 +616,8 @@ make_process (Lisp_Object name)
616{ 616{
617 register Lisp_Object val, tem, name1; 617 register Lisp_Object val, tem, name1;
618 register struct Lisp_Process *p; 618 register struct Lisp_Process *p;
619 char suffix[10]; 619 char suffix[sizeof "<>" + INT_STRLEN_BOUND (printmax_t)];
620 register int i; 620 printmax_t i;
621 621
622 p = allocate_process (); 622 p = allocate_process ();
623 623
@@ -651,7 +651,7 @@ make_process (Lisp_Object name)
651 { 651 {
652 tem = Fget_process (name1); 652 tem = Fget_process (name1);
653 if (NILP (tem)) break; 653 if (NILP (tem)) break;
654 sprintf (suffix, "<%d>", i); 654 sprintf (suffix, "<%"pMd">", i);
655 name1 = concat2 (name, build_string (suffix)); 655 name1 = concat2 (name, build_string (suffix));
656 } 656 }
657 name = name1; 657 name = name1;
diff --git a/src/search.c b/src/search.c
index d892792cbaa..b3d67e6c431 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2404,7 +2404,7 @@ since only regular expressions have distinguished subexpressions. */)
2404 int some_uppercase; 2404 int some_uppercase;
2405 int some_nonuppercase_initial; 2405 int some_nonuppercase_initial;
2406 register int c, prevc; 2406 register int c, prevc;
2407 int sub; 2407 ptrdiff_t sub;
2408 EMACS_INT opoint, newpoint; 2408 EMACS_INT opoint, newpoint;
2409 2409
2410 CHECK_STRING (newtext); 2410 CHECK_STRING (newtext);
@@ -2423,9 +2423,9 @@ since only regular expressions have distinguished subexpressions. */)
2423 else 2423 else
2424 { 2424 {
2425 CHECK_NUMBER (subexp); 2425 CHECK_NUMBER (subexp);
2426 sub = XINT (subexp); 2426 if (! (0 <= XINT (subexp) && XINT (subexp) < search_regs.num_regs))
2427 if (sub < 0 || sub >= search_regs.num_regs)
2428 args_out_of_range (subexp, make_number (search_regs.num_regs)); 2427 args_out_of_range (subexp, make_number (search_regs.num_regs));
2428 sub = XINT (subexp);
2429 } 2429 }
2430 2430
2431 if (NILP (string)) 2431 if (NILP (string))
@@ -2662,7 +2662,7 @@ since only regular expressions have distinguished subexpressions. */)
2662 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2662 unsigned char str[MAX_MULTIBYTE_LENGTH];
2663 const unsigned char *add_stuff = NULL; 2663 const unsigned char *add_stuff = NULL;
2664 ptrdiff_t add_len = 0; 2664 ptrdiff_t add_len = 0;
2665 int idx = -1; 2665 ptrdiff_t idx = -1;
2666 2666
2667 if (str_multibyte) 2667 if (str_multibyte)
2668 { 2668 {
@@ -2813,7 +2813,7 @@ since only regular expressions have distinguished subexpressions. */)
2813static Lisp_Object 2813static Lisp_Object
2814match_limit (Lisp_Object num, int beginningp) 2814match_limit (Lisp_Object num, int beginningp)
2815{ 2815{
2816 register int n; 2816 EMACS_INT n;
2817 2817
2818 CHECK_NUMBER (num); 2818 CHECK_NUMBER (num);
2819 n = XINT (num); 2819 n = XINT (num);
diff --git a/src/sysdep.c b/src/sysdep.c
index 57fff94f552..e20bd591da1 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1811,6 +1811,45 @@ strerror (int errnum)
1811} 1811}
1812#endif /* not WINDOWSNT */ 1812#endif /* not WINDOWSNT */
1813#endif /* ! HAVE_STRERROR */ 1813#endif /* ! HAVE_STRERROR */
1814
1815#ifndef HAVE_SNPRINTF
1816/* Approximate snprintf as best we can on ancient hosts that lack it. */
1817int
1818snprintf (char *buf, size_t bufsize, char const *format, ...)
1819{
1820 ptrdiff_t size = min (bufsize, PTRDIFF_MAX);
1821 ptrdiff_t nbytes = size - 1;
1822 va_list ap;
1823
1824 if (size)
1825 {
1826 va_start (ap, format);
1827 nbytes = doprnt (buf, size, format, 0, ap);
1828 va_end (ap);
1829 }
1830
1831 if (nbytes == size - 1)
1832 {
1833 /* Calculate the length of the string that would have been created
1834 had the buffer been large enough. */
1835 char stackbuf[4000];
1836 char *b = stackbuf;
1837 ptrdiff_t bsize = sizeof stackbuf;
1838 va_start (ap, format);
1839 nbytes = evxprintf (&b, &bsize, stackbuf, -1, format, ap);
1840 va_end (ap);
1841 if (b != stackbuf)
1842 xfree (b);
1843 }
1844
1845 if (INT_MAX < nbytes)
1846 {
1847 errno = EOVERFLOW;
1848 return -1;
1849 }
1850 return nbytes;
1851}
1852#endif
1814 1853
1815int 1854int
1816emacs_open (const char *path, int oflag, int mode) 1855emacs_open (const char *path, int oflag, int mode)
diff --git a/src/term.c b/src/term.c
index 837ab399152..10416090b80 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1817,7 +1817,7 @@ produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
1817{ 1817{
1818 int face_id; 1818 int face_id;
1819 int len; 1819 int len;
1820 char buf[9]; 1820 char buf[sizeof "\\x" + max (6, (sizeof it->c * CHAR_BIT + 3) / 4)];
1821 char const *str = " "; 1821 char const *str = " ";
1822 1822
1823 /* Get a face ID for the glyph by utilizing a cache (the same way as 1823 /* Get a face ID for the glyph by utilizing a cache (the same way as
diff --git a/src/window.c b/src/window.c
index 96b1144acf2..e3850387a64 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4662,14 +4662,9 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4662 4662
4663 if (pos < ZV) 4663 if (pos < ZV)
4664 { 4664 {
4665 int this_scroll_margin = scroll_margin;
4666
4667 /* Don't use a scroll margin that is negative or too large. */ 4665 /* Don't use a scroll margin that is negative or too large. */
4668 if (this_scroll_margin < 0) 4666 int this_scroll_margin =
4669 this_scroll_margin = 0; 4667 max (0, min (scroll_margin, XINT (w->total_lines) / 4));
4670
4671 if (XINT (w->total_lines) < 4 * scroll_margin)
4672 this_scroll_margin = XINT (w->total_lines) / 4;
4673 4668
4674 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); 4669 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4675 w->start_at_line_beg = bolp; 4670 w->start_at_line_beg = bolp;
@@ -5057,7 +5052,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5057 struct buffer *obuf = current_buffer; 5052 struct buffer *obuf = current_buffer;
5058 int center_p = 0; 5053 int center_p = 0;
5059 EMACS_INT charpos, bytepos; 5054 EMACS_INT charpos, bytepos;
5060 int iarg IF_LINT (= 0); 5055 EMACS_INT iarg IF_LINT (= 0);
5061 int this_scroll_margin; 5056 int this_scroll_margin;
5062 5057
5063 /* If redisplay is suppressed due to an error, try again. */ 5058 /* If redisplay is suppressed due to an error, try again. */
@@ -5096,9 +5091,8 @@ and redisplay normally--don't erase and redraw the frame. */)
5096 5091
5097 /* Do this after making BUF current 5092 /* Do this after making BUF current
5098 in case scroll_margin is buffer-local. */ 5093 in case scroll_margin is buffer-local. */
5099 this_scroll_margin = max (0, scroll_margin); 5094 this_scroll_margin =
5100 this_scroll_margin = min (this_scroll_margin, 5095 max (0, min (scroll_margin, XFASTINT (w->total_lines) / 4));
5101 XFASTINT (w->total_lines) / 4);
5102 5096
5103 /* Handle centering on a graphical frame specially. Such frames can 5097 /* Handle centering on a graphical frame specially. Such frames can
5104 have variable-height lines and centering point on the basis of 5098 have variable-height lines and centering point on the basis of
@@ -5122,7 +5116,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5122 { 5116 {
5123 struct it it; 5117 struct it it;
5124 struct text_pos pt; 5118 struct text_pos pt;
5125 int nlines = -iarg; 5119 int nlines = min (INT_MAX, -iarg);
5126 int extra_line_spacing; 5120 int extra_line_spacing;
5127 int h = window_box_height (w); 5121 int h = window_box_height (w);
5128 void *itdata = bidi_shelve_cache (); 5122 void *itdata = bidi_shelve_cache ();
@@ -5288,15 +5282,14 @@ zero means top of window, negative means relative to bottom of window. */)
5288 lines = displayed_window_lines (w); 5282 lines = displayed_window_lines (w);
5289 5283
5290#if 0 5284#if 0
5291 this_scroll_margin = max (0, scroll_margin); 5285 this_scroll_margin = max (0, min (scroll_margin, lines / 4));
5292 this_scroll_margin = min (this_scroll_margin, lines / 4);
5293#endif 5286#endif
5294 5287
5295 if (NILP (arg)) 5288 if (NILP (arg))
5296 XSETFASTINT (arg, lines / 2); 5289 XSETFASTINT (arg, lines / 2);
5297 else 5290 else
5298 { 5291 {
5299 int iarg = XINT (Fprefix_numeric_value (arg)); 5292 EMACS_INT iarg = XINT (Fprefix_numeric_value (arg));
5300 5293
5301 if (iarg < 0) 5294 if (iarg < 0)
5302 iarg = iarg + lines; 5295 iarg = iarg + lines;
@@ -5468,7 +5461,8 @@ the return value is nil. Otherwise the value is t. */)
5468 struct window *root_window; 5461 struct window *root_window;
5469 struct window **leaf_windows; 5462 struct window **leaf_windows;
5470 int n_leaf_windows; 5463 int n_leaf_windows;
5471 int k, i, n; 5464 ptrdiff_t k;
5465 int i, n;
5472 5466
5473 /* If the frame has been resized since this window configuration was 5467 /* If the frame has been resized since this window configuration was
5474 made, we change the frame to the size specified in the 5468 made, we change the frame to the size specified in the
@@ -6344,7 +6338,7 @@ compare_window_configurations (Lisp_Object configuration1, Lisp_Object configura
6344{ 6338{
6345 register struct save_window_data *d1, *d2; 6339 register struct save_window_data *d1, *d2;
6346 struct Lisp_Vector *sws1, *sws2; 6340 struct Lisp_Vector *sws1, *sws2;
6347 int i; 6341 ptrdiff_t i;
6348 6342
6349 CHECK_WINDOW_CONFIGURATION (configuration1); 6343 CHECK_WINDOW_CONFIGURATION (configuration1);
6350 CHECK_WINDOW_CONFIGURATION (configuration2); 6344 CHECK_WINDOW_CONFIGURATION (configuration2);
diff --git a/src/window.h b/src/window.h
index 485734e907e..c6fa5e7a338 100644
--- a/src/window.h
+++ b/src/window.h
@@ -847,11 +847,11 @@ extern Lisp_Object echo_area_window;
847 847
848/* Depth in recursive edits. */ 848/* Depth in recursive edits. */
849 849
850extern int command_loop_level; 850extern EMACS_INT command_loop_level;
851 851
852/* Depth in minibuffer invocations. */ 852/* Depth in minibuffer invocations. */
853 853
854extern int minibuf_level; 854extern EMACS_INT minibuf_level;
855 855
856/* true if we should redraw the mode lines on the next redisplay. */ 856/* true if we should redraw the mode lines on the next redisplay. */
857 857
diff --git a/src/xdisp.c b/src/xdisp.c
index 1716cc82188..f11362c1ae6 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -16919,8 +16919,8 @@ try_window_id (struct window *w)
16919 { 16919 {
16920 int this_scroll_margin, cursor_height; 16920 int this_scroll_margin, cursor_height;
16921 16921
16922 this_scroll_margin = max (0, scroll_margin); 16922 this_scroll_margin =
16923 this_scroll_margin = min (this_scroll_margin, WINDOW_TOTAL_LINES (w) / 4); 16923 max (0, min (scroll_margin, WINDOW_TOTAL_LINES (w) / 4));
16924 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f); 16924 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
16925 cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; 16925 cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height;
16926 16926
diff --git a/src/xfaces.c b/src/xfaces.c
index 431ca07b8df..47d55f4da4b 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -3549,6 +3549,8 @@ x_update_menu_appearance (struct frame *f)
3549 rdb != NULL)) 3549 rdb != NULL))
3550 { 3550 {
3551 char line[512]; 3551 char line[512];
3552 char *buf = line;
3553 ptrdiff_t bufsize = sizeof line;
3552 Lisp_Object lface = lface_from_face_name (f, Qmenu, 1); 3554 Lisp_Object lface = lface_from_face_name (f, Qmenu, 1);
3553 struct face *face = FACE_FROM_ID (f, MENU_FACE_ID); 3555 struct face *face = FACE_FROM_ID (f, MENU_FACE_ID);
3554 const char *myname = SSDATA (Vx_resource_name); 3556 const char *myname = SSDATA (Vx_resource_name);
@@ -3561,24 +3563,25 @@ x_update_menu_appearance (struct frame *f)
3561 3563
3562 if (STRINGP (LFACE_FOREGROUND (lface))) 3564 if (STRINGP (LFACE_FOREGROUND (lface)))
3563 { 3565 {
3564 sprintf (line, "%s.%s*foreground: %s", 3566 exprintf (&buf, &bufsize, line, -1, "%s.%s*foreground: %s",
3565 myname, popup_path, 3567 myname, popup_path,
3566 SDATA (LFACE_FOREGROUND (lface))); 3568 SDATA (LFACE_FOREGROUND (lface)));
3567 XrmPutLineResource (&rdb, line); 3569 XrmPutLineResource (&rdb, line);
3568 sprintf (line, "%s.pane.menubar*foreground: %s", 3570 exprintf (&buf, &bufsize, line, -1, "%s.pane.menubar*foreground: %s",
3569 myname, SDATA (LFACE_FOREGROUND (lface))); 3571 myname, SDATA (LFACE_FOREGROUND (lface)));
3570 XrmPutLineResource (&rdb, line); 3572 XrmPutLineResource (&rdb, line);
3571 changed_p = 1; 3573 changed_p = 1;
3572 } 3574 }
3573 3575
3574 if (STRINGP (LFACE_BACKGROUND (lface))) 3576 if (STRINGP (LFACE_BACKGROUND (lface)))
3575 { 3577 {
3576 sprintf (line, "%s.%s*background: %s", 3578 exprintf (&buf, &bufsize, line, -1, "%s.%s*background: %s",
3577 myname, popup_path, 3579 myname, popup_path,
3578 SDATA (LFACE_BACKGROUND (lface))); 3580 SDATA (LFACE_BACKGROUND (lface)));
3579 XrmPutLineResource (&rdb, line); 3581 XrmPutLineResource (&rdb, line);
3580 sprintf (line, "%s.pane.menubar*background: %s", 3582
3581 myname, SDATA (LFACE_BACKGROUND (lface))); 3583 exprintf (&buf, &bufsize, line, -1, "%s.pane.menubar*background: %s",
3584 myname, SDATA (LFACE_BACKGROUND (lface)));
3582 XrmPutLineResource (&rdb, line); 3585 XrmPutLineResource (&rdb, line);
3583 changed_p = 1; 3586 changed_p = 1;
3584 } 3587 }
@@ -3616,11 +3619,12 @@ x_update_menu_appearance (struct frame *f)
3616#else 3619#else
3617 char *fontsetname = SSDATA (xlfd); 3620 char *fontsetname = SSDATA (xlfd);
3618#endif 3621#endif
3619 sprintf (line, "%s.pane.menubar*font%s: %s", 3622 exprintf (&buf, &bufsize, line, -1, "%s.pane.menubar*font%s: %s",
3620 myname, suffix, fontsetname); 3623 myname, suffix, fontsetname);
3621 XrmPutLineResource (&rdb, line); 3624 XrmPutLineResource (&rdb, line);
3622 sprintf (line, "%s.%s*font%s: %s", 3625
3623 myname, popup_path, suffix, fontsetname); 3626 exprintf (&buf, &bufsize, line, -1, "%s.%s*font%s: %s",
3627 myname, popup_path, suffix, fontsetname);
3624 XrmPutLineResource (&rdb, line); 3628 XrmPutLineResource (&rdb, line);
3625 changed_p = 1; 3629 changed_p = 1;
3626 if (fontsetname != SSDATA (xlfd)) 3630 if (fontsetname != SSDATA (xlfd))
@@ -3630,6 +3634,9 @@ x_update_menu_appearance (struct frame *f)
3630 3634
3631 if (changed_p && f->output_data.x->menubar_widget) 3635 if (changed_p && f->output_data.x->menubar_widget)
3632 free_frame_menubar (f); 3636 free_frame_menubar (f);
3637
3638 if (buf != line)
3639 xfree (buf);
3633 } 3640 }
3634} 3641}
3635 3642
diff --git a/src/xfns.c b/src/xfns.c
index 9a3d5fcda83..194a8f063b7 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -2440,7 +2440,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2440 /* Do some needed geometry management. */ 2440 /* Do some needed geometry management. */
2441 { 2441 {
2442 ptrdiff_t len; 2442 ptrdiff_t len;
2443 char *tem, shell_position[32]; 2443 char *tem, shell_position[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2444 Arg gal[10]; 2444 Arg gal[10];
2445 int gac = 0; 2445 int gac = 0;
2446 int extra_borders = 0; 2446 int extra_borders = 0;
diff --git a/src/xml.c b/src/xml.c
index 55352baae3a..8b485e73649 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -141,7 +141,6 @@ parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int html
141 Fcons (Qnil, Fnreverse (Fcons (r, result)))); 141 Fcons (Qnil, Fnreverse (Fcons (r, result))));
142 142
143 xmlFreeDoc (doc); 143 xmlFreeDoc (doc);
144 xmlCleanupParser ();
145 } 144 }
146 145
147 return result; 146 return result;
diff --git a/src/xterm.c b/src/xterm.c
index c07caec6c78..86393cf411f 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -7900,7 +7900,8 @@ x_io_error_quitter (Display *display)
7900{ 7900{
7901 char buf[256]; 7901 char buf[256];
7902 7902
7903 sprintf (buf, "Connection lost to X server `%s'", DisplayString (display)); 7903 snprintf (buf, sizeof buf, "Connection lost to X server `%s'",
7904 DisplayString (display));
7904 x_connection_closed (display, buf); 7905 x_connection_closed (display, buf);
7905 return 0; 7906 return 0;
7906} 7907}
diff --git a/src/xterm.h b/src/xterm.h
index 30867656710..fe86a32d09f 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -955,7 +955,8 @@ XrmDatabase x_load_resources (Display *, const char *, const char *,
955extern int x_text_icon (struct frame *, const char *); 955extern int x_text_icon (struct frame *, const char *);
956extern int x_bitmap_icon (struct frame *, Lisp_Object); 956extern int x_bitmap_icon (struct frame *, Lisp_Object);
957extern void x_catch_errors (Display *); 957extern void x_catch_errors (Display *);
958extern void x_check_errors (Display *, const char *); 958extern void x_check_errors (Display *, const char *)
959 ATTRIBUTE_FORMAT_PRINTF (2, 0);
959extern int x_had_errors_p (Display *); 960extern int x_had_errors_p (Display *);
960extern int x_catching_errors (void); 961extern int x_catching_errors (void);
961extern void x_uncatch_errors (void); 962extern void x_uncatch_errors (void);