aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-09-05 13:43:14 -0700
committerPaul Eggert2011-09-05 13:43:14 -0700
commit1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67 (patch)
tree8c3e07779650c446922a93839c3ecdabb85cdaea /src
parentf4af5137d41b5ff71771028385f89be889dd1315 (diff)
parent697210c4822d4e7be9a81234d2026e5ace724a90 (diff)
downloademacs-1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67.tar.gz
emacs-1dc4aa6d975c9f92cd5c0d0baf5eae89e013fd67.zip
Merge from trunk.
Diffstat (limited to 'src')
-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
34 files changed, 724 insertions, 367 deletions
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);