aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2019-07-07 12:29:27 -0700
committerPaul Eggert2019-07-07 12:33:35 -0700
commit8f522efe9a963cd3523ea6863f9bd44881cdf6b7 (patch)
tree10ba28c937e142395bcc4d81580d24fa334e1227 /src
parentbda8a57141e6cb5455e1246c6ab394791fd6c582 (diff)
downloademacs-8f522efe9a963cd3523ea6863f9bd44881cdf6b7.tar.gz
emacs-8f522efe9a963cd3523ea6863f9bd44881cdf6b7.zip
Remove printmax_t etc.
printmax_t etc. were needed only for platforms that lacked support for printing intmax_t. These platforms are now so obsolete that they are no longer practical porting targets. * src/image.c (gs_load): Fix unlikely buffer overrun discovered while making these changes. It was introduced in 2011-07-17T00:34:43!eggert@cs.ucla.edu. * src/lisp.h (printmax_t, uprintmax_t, pMd, pMu, pMx): Remove. All uses replaced by their standard counterparts intmax_t, uintmax_t, PRIdMAX, PRIuMAX, PRIxMAX.
Diffstat (limited to 'src')
-rw-r--r--src/dbusbind.c18
-rw-r--r--src/dispnew.c6
-rw-r--r--src/doprnt.c8
-rw-r--r--src/editfns.c14
-rw-r--r--src/emacs.c5
-rw-r--r--src/filelock.c8
-rw-r--r--src/font.c6
-rw-r--r--src/frame.c16
-rw-r--r--src/gnutls.c4
-rw-r--r--src/image.c10
-rw-r--r--src/lisp.h19
-rw-r--r--src/print.c22
-rw-r--r--src/process.c6
-rw-r--r--src/sysdep.c8
-rw-r--r--src/timefns.c4
-rw-r--r--src/unexelf.c3
-rw-r--r--src/xdisp.c7
-rw-r--r--src/xselect.c8
18 files changed, 77 insertions, 95 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 850d176c08f..90ba461c6bc 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -661,8 +661,8 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter)
661 xd_extract_signed (object, 661 xd_extract_signed (object,
662 TYPE_MINIMUM (dbus_int64_t), 662 TYPE_MINIMUM (dbus_int64_t),
663 TYPE_MAXIMUM (dbus_int64_t)); 663 TYPE_MAXIMUM (dbus_int64_t));
664 printmax_t pval = val; 664 intmax_t pval = val;
665 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); 665 XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval);
666 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 666 if (!dbus_message_iter_append_basic (iter, dtype, &val))
667 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 667 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
668 return; 668 return;
@@ -673,8 +673,8 @@ xd_append_arg (int dtype, Lisp_Object object, DBusMessageIter *iter)
673 dbus_uint64_t val = 673 dbus_uint64_t val =
674 xd_extract_unsigned (object, 674 xd_extract_unsigned (object,
675 TYPE_MAXIMUM (dbus_uint64_t)); 675 TYPE_MAXIMUM (dbus_uint64_t));
676 uprintmax_t pval = val; 676 uintmax_t pval = val;
677 XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); 677 XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval);
678 if (!dbus_message_iter_append_basic (iter, dtype, &val)) 678 if (!dbus_message_iter_append_basic (iter, dtype, &val))
679 XD_SIGNAL2 (build_string ("Unable to append argument"), object); 679 XD_SIGNAL2 (build_string ("Unable to append argument"), object);
680 return; 680 return;
@@ -867,20 +867,18 @@ xd_retrieve_arg (int dtype, DBusMessageIter *iter)
867 case DBUS_TYPE_INT64: 867 case DBUS_TYPE_INT64:
868 { 868 {
869 dbus_int64_t val; 869 dbus_int64_t val;
870 printmax_t pval;
871 dbus_message_iter_get_basic (iter, &val); 870 dbus_message_iter_get_basic (iter, &val);
872 pval = val; 871 intmax_t pval = val;
873 XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval); 872 XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval);
874 return INT_TO_INTEGER (val); 873 return INT_TO_INTEGER (val);
875 } 874 }
876 875
877 case DBUS_TYPE_UINT64: 876 case DBUS_TYPE_UINT64:
878 { 877 {
879 dbus_uint64_t val; 878 dbus_uint64_t val;
880 uprintmax_t pval;
881 dbus_message_iter_get_basic (iter, &val); 879 dbus_message_iter_get_basic (iter, &val);
882 pval = val; 880 uintmax_t pval = val;
883 XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval); 881 XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval);
884 return INT_TO_INTEGER (val); 882 return INT_TO_INTEGER (val);
885 } 883 }
886 884
diff --git a/src/dispnew.c b/src/dispnew.c
index 52a7b6d6ee0..5a6662e0f3b 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -157,7 +157,7 @@ static int history_idx;
157/* A tick that's incremented each time something is added to the 157/* A tick that's incremented each time something is added to the
158 history. */ 158 history. */
159 159
160static uprintmax_t history_tick; 160static uintmax_t history_tick;
161 161
162/* Add to the redisplay history how window W has been displayed. 162/* Add to the redisplay history how window W has been displayed.
163 MSG is a trace containing the information how W's glyph matrix 163 MSG is a trace containing the information how W's glyph matrix
@@ -176,7 +176,7 @@ add_window_display_history (struct window *w, const char *msg, bool paused_p)
176 ++history_idx; 176 ++history_idx;
177 177
178 snprintf (buf, sizeof redisplay_history[0].trace, 178 snprintf (buf, sizeof redisplay_history[0].trace,
179 "%"pMu": window %p (%s)%s\n%s", 179 "%"PRIuMAX": window %p (%s)%s\n%s",
180 history_tick++, 180 history_tick++,
181 ptr, 181 ptr,
182 ((BUFFERP (w->contents) 182 ((BUFFERP (w->contents)
@@ -203,7 +203,7 @@ add_frame_display_history (struct frame *f, bool paused_p)
203 buf = redisplay_history[history_idx].trace; 203 buf = redisplay_history[history_idx].trace;
204 ++history_idx; 204 ++history_idx;
205 205
206 sprintf (buf, "%"pMu": update frame %p%s", 206 sprintf (buf, "%"PRIuMAX": update frame %p%s",
207 history_tick++, 207 history_tick++,
208 ptr, paused_p ? " ***paused***" : ""); 208 ptr, paused_p ? " ***paused***" : "");
209} 209}
diff --git a/src/doprnt.c b/src/doprnt.c
index 64bb368ee3e..819700f6798 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -71,7 +71,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
71 %<flags><width><precision><length>character 71 %<flags><width><precision><length>character
72 72
73 where flags is [+ -0], width is [0-9]+, precision is .[0-9]+, and length 73 where flags is [+ -0], width is [0-9]+, precision is .[0-9]+, and length
74 is empty or l or the value of the pD or pI or pMd (sans "d") macros. 74 is empty or l or the value of the pD or pI or PRIdMAX (sans "d") macros.
75 Also, %% in a format stands for a single % in the output. A % that 75 Also, %% in a format stands for a single % in the output. A % that
76 does not introduce a valid %-sequence causes undefined behavior. 76 does not introduce a valid %-sequence causes undefined behavior.
77 77
@@ -88,7 +88,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
88 the respective argument is to be treated as `long int' or `unsigned long 88 the respective argument is to be treated as `long int' or `unsigned long
89 int'. Similarly, the value of the pD macro means to use ptrdiff_t, 89 int'. Similarly, the value of the pD macro means to use ptrdiff_t,
90 the value of the pI macro means to use EMACS_INT or EMACS_UINT, the 90 the value of the pI macro means to use EMACS_INT or EMACS_UINT, the
91 value of the pMd etc. macros means to use intmax_t or uintmax_t, 91 value of the PRIdMAX etc. macros means to use intmax_t or uintmax_t,
92 and the empty length modifier means `int' or `unsigned int'. 92 and the empty length modifier means `int' or `unsigned int'.
93 93
94 The width specifier supplies a lower limit for the length of the printed 94 The width specifier supplies a lower limit for the length of the printed
@@ -179,7 +179,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
179 enum { 179 enum {
180 pDlen = sizeof pD - 1, 180 pDlen = sizeof pD - 1,
181 pIlen = sizeof pI - 1, 181 pIlen = sizeof pI - 1,
182 pMlen = sizeof pMd - 2 182 pMlen = sizeof PRIdMAX - 2
183 }; 183 };
184 enum { 184 enum {
185 no_modifier, long_modifier, pD_modifier, pI_modifier, pM_modifier 185 no_modifier, long_modifier, pD_modifier, pI_modifier, pM_modifier
@@ -234,7 +234,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
234 length_modifier = pD_modifier; 234 length_modifier = pD_modifier;
235 if (mlen == pIlen && memcmp (fmt, pI, pIlen) == 0) 235 if (mlen == pIlen && memcmp (fmt, pI, pIlen) == 0)
236 length_modifier = pI_modifier; 236 length_modifier = pI_modifier;
237 if (mlen == pMlen && memcmp (fmt, pMd, pMlen) == 0) 237 if (mlen == pMlen && memcmp (fmt, PRIdMAX, pMlen) == 0)
238 length_modifier = pM_modifier; 238 length_modifier = pM_modifier;
239 } 239 }
240 240
diff --git a/src/editfns.c b/src/editfns.c
index ee538e50e25..fd9fbaeaea2 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3477,8 +3477,8 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3477 error ("Format specifier doesn't match argument type"); 3477 error ("Format specifier doesn't match argument type");
3478 else 3478 else
3479 { 3479 {
3480 /* Length of pM (that is, of pMd without the trailing "d"). */ 3480 /* Length of PRIdMAX without the trailing "d". */
3481 enum { pMlen = sizeof pMd - 2 }; 3481 enum { pMlen = sizeof PRIdMAX - 2 };
3482 3482
3483 /* Avoid undefined behavior in underlying sprintf. */ 3483 /* Avoid undefined behavior in underlying sprintf. */
3484 if (conversion == 'd' || conversion == 'i') 3484 if (conversion == 'd' || conversion == 'i')
@@ -3487,7 +3487,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3487 /* Create the copy of the conversion specification, with 3487 /* Create the copy of the conversion specification, with
3488 any width and precision removed, with ".*" inserted, 3488 any width and precision removed, with ".*" inserted,
3489 with "L" possibly inserted for floating-point formats, 3489 with "L" possibly inserted for floating-point formats,
3490 and with pM inserted for integer formats. 3490 and with PRIdMAX (sans "d") inserted for integer formats.
3491 At most two flags F can be specified at once. */ 3491 At most two flags F can be specified at once. */
3492 char convspec[sizeof "%FF.*d" + max (sizeof "L" - 1, pMlen)]; 3492 char convspec[sizeof "%FF.*d" + max (sizeof "L" - 1, pMlen)];
3493 char *f = convspec; 3493 char *f = convspec;
@@ -3616,7 +3616,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3616 { 3616 {
3617 if (FIXNUMP (arg)) 3617 if (FIXNUMP (arg))
3618 { 3618 {
3619 printmax_t x = XFIXNUM (arg); 3619 intmax_t x = XFIXNUM (arg);
3620 sprintf_bytes = sprintf (p, convspec, prec, x); 3620 sprintf_bytes = sprintf (p, convspec, prec, x);
3621 } 3621 }
3622 else 3622 else
@@ -3636,7 +3636,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3636 } 3636 }
3637 else 3637 else
3638 { 3638 {
3639 uprintmax_t x; 3639 uintmax_t x;
3640 bool negative; 3640 bool negative;
3641 if (FIXNUMP (arg)) 3641 if (FIXNUMP (arg))
3642 { 3642 {
@@ -3655,8 +3655,8 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3655 else 3655 else
3656 { 3656 {
3657 double d = XFLOAT_DATA (arg); 3657 double d = XFLOAT_DATA (arg);
3658 double uprintmax = TYPE_MAXIMUM (uprintmax_t); 3658 double uintmax = UINTMAX_MAX;
3659 if (! (0 <= d && d < uprintmax + 1)) 3659 if (! (0 <= d && d < uintmax + 1))
3660 xsignal1 (Qoverflow_error, arg); 3660 xsignal1 (Qoverflow_error, arg);
3661 x = d; 3661 x = d;
3662 negative = false; 3662 negative = false;
diff --git a/src/emacs.c b/src/emacs.c
index fc1a4beec50..0f03dd656d3 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -150,7 +150,7 @@ bool display_arg;
150 150
151#if defined GNU_LINUX && defined HAVE_UNEXEC 151#if defined GNU_LINUX && defined HAVE_UNEXEC
152/* The gap between BSS end and heap start as far as we can tell. */ 152/* The gap between BSS end and heap start as far as we can tell. */
153static uprintmax_t heap_bss_diff; 153static uintmax_t heap_bss_diff;
154#endif 154#endif
155 155
156/* To run as a background daemon under Cocoa or Windows, 156/* To run as a background daemon under Cocoa or Windows,
@@ -2548,7 +2548,8 @@ You must run Emacs in batch mode in order to dump it. */)
2548 { 2548 {
2549 fprintf (stderr, "**************************************************\n"); 2549 fprintf (stderr, "**************************************************\n");
2550 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n"); 2550 fprintf (stderr, "Warning: Your system has a gap between BSS and the\n");
2551 fprintf (stderr, "heap (%"pMu" bytes). This usually means that exec-shield\n", 2551 fprintf (stderr, ("heap (%"PRIuMAX" bytes). "
2552 "This usually means that exec-shield\n"),
2552 heap_bss_diff); 2553 heap_bss_diff);
2553 fprintf (stderr, "or something similar is in effect. The dump may\n"); 2554 fprintf (stderr, "or something similar is in effect. The dump may\n");
2554 fprintf (stderr, "fail because of this. See the section about\n"); 2555 fprintf (stderr, "fail because of this. See the section about\n");
diff --git a/src/filelock.c b/src/filelock.c
index b1f7d9dce61..46349a63e4a 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -429,26 +429,26 @@ static int
429lock_file_1 (char *lfname, bool force) 429lock_file_1 (char *lfname, bool force)
430{ 430{
431 /* Call this first because it can GC. */ 431 /* Call this first because it can GC. */
432 printmax_t boot = get_boot_time (); 432 intmax_t boot = get_boot_time ();
433 433
434 Lisp_Object luser_name = Fuser_login_name (Qnil); 434 Lisp_Object luser_name = Fuser_login_name (Qnil);
435 char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : ""; 435 char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : "";
436 Lisp_Object lhost_name = Fsystem_name (); 436 Lisp_Object lhost_name = Fsystem_name ();
437 char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : ""; 437 char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : "";
438 char lock_info_str[MAX_LFINFO + 1]; 438 char lock_info_str[MAX_LFINFO + 1];
439 printmax_t pid = getpid (); 439 intmax_t pid = getpid ();
440 440
441 if (boot) 441 if (boot)
442 { 442 {
443 if (sizeof lock_info_str 443 if (sizeof lock_info_str
444 <= snprintf (lock_info_str, sizeof lock_info_str, 444 <= snprintf (lock_info_str, sizeof lock_info_str,
445 "%s@%s.%"pMd":%"pMd, 445 "%s@%s.%"PRIdMAX":%"PRIdMAX,
446 user_name, host_name, pid, boot)) 446 user_name, host_name, pid, boot))
447 return ENAMETOOLONG; 447 return ENAMETOOLONG;
448 } 448 }
449 else if (sizeof lock_info_str 449 else if (sizeof lock_info_str
450 <= snprintf (lock_info_str, sizeof lock_info_str, 450 <= snprintf (lock_info_str, sizeof lock_info_str,
451 "%s@%s.%"pMd, 451 "%s@%s.%"PRIdMAX,
452 user_name, host_name, pid)) 452 user_name, host_name, pid))
453 return ENAMETOOLONG; 453 return ENAMETOOLONG;
454 454
diff --git a/src/font.c b/src/font.c
index 409ffa6ae0c..b4a85a1ca5a 100644
--- a/src/font.c
+++ b/src/font.c
@@ -1295,14 +1295,12 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1295 if (INTEGERP (val)) 1295 if (INTEGERP (val))
1296 { 1296 {
1297 intmax_t v; 1297 intmax_t v;
1298 if (! (integer_to_intmax (val, &v) 1298 if (! (integer_to_intmax (val, &v) && 0 < v))
1299 && 0 < v && v <= TYPE_MAXIMUM (uprintmax_t)))
1300 v = pixel_size; 1299 v = pixel_size;
1301 if (v > 0) 1300 if (v > 0)
1302 { 1301 {
1303 uprintmax_t u = v;
1304 f[XLFD_PIXEL_INDEX] = p = font_size_index_buf; 1302 f[XLFD_PIXEL_INDEX] = p = font_size_index_buf;
1305 sprintf (p, "%"pMu"-*", u); 1303 sprintf (p, "%"PRIdMAX"-*", v);
1306 } 1304 }
1307 else 1305 else
1308 f[XLFD_PIXEL_INDEX] = "*-*"; 1306 f[XLFD_PIXEL_INDEX] = "*-*";
diff --git a/src/frame.c b/src/frame.c
index 03bbbfb4da2..6363a873684 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1048,7 +1048,7 @@ make_minibuffer_frame (void)
1048 1048
1049/* Construct a frame that refers to a terminal. */ 1049/* Construct a frame that refers to a terminal. */
1050 1050
1051static printmax_t tty_frame_count; 1051static intmax_t tty_frame_count;
1052 1052
1053struct frame * 1053struct frame *
1054make_initial_frame (void) 1054make_initial_frame (void)
@@ -1108,7 +1108,7 @@ make_terminal_frame (struct terminal *terminal)
1108{ 1108{
1109 register struct frame *f; 1109 register struct frame *f;
1110 Lisp_Object frame; 1110 Lisp_Object frame;
1111 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)]; 1111 char name[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)];
1112 1112
1113 if (!terminal->name) 1113 if (!terminal->name)
1114 error ("Terminal is not live, can't create new frames on it"); 1114 error ("Terminal is not live, can't create new frames on it");
@@ -1118,7 +1118,7 @@ make_terminal_frame (struct terminal *terminal)
1118 XSETFRAME (frame, f); 1118 XSETFRAME (frame, f);
1119 Vframe_list = Fcons (frame, Vframe_list); 1119 Vframe_list = Fcons (frame, Vframe_list);
1120 1120
1121 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count)); 1121 fset_name (f, make_formatted_string (name, "F%"PRIdMAX, ++tty_frame_count));
1122 1122
1123 SET_FRAME_VISIBLE (f, 1); 1123 SET_FRAME_VISIBLE (f, 1);
1124 1124
@@ -2920,14 +2920,14 @@ set_term_frame_name (struct frame *f, Lisp_Object name)
2920 /* If NAME is nil, set the name to F<num>. */ 2920 /* If NAME is nil, set the name to F<num>. */
2921 if (NILP (name)) 2921 if (NILP (name))
2922 { 2922 {
2923 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)]; 2923 char namebuf[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)];
2924 2924
2925 /* Check for no change needed in this very common case 2925 /* Check for no change needed in this very common case
2926 before we do any consing. */ 2926 before we do any consing. */
2927 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name))) 2927 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2928 return; 2928 return;
2929 2929
2930 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count); 2930 name = make_formatted_string (namebuf, "F%"PRIdMAX, ++tty_frame_count);
2931 } 2931 }
2932 else 2932 else
2933 { 2933 {
@@ -4201,7 +4201,7 @@ void
4201gui_report_frame_params (struct frame *f, Lisp_Object *alistptr) 4201gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4202{ 4202{
4203 Lisp_Object tem; 4203 Lisp_Object tem;
4204 uprintmax_t w; 4204 uintmax_t w;
4205 char buf[INT_BUFSIZE_BOUND (w)]; 4205 char buf[INT_BUFSIZE_BOUND (w)];
4206 4206
4207 /* Represent negative positions (off the top or left screen edge) 4207 /* Represent negative positions (off the top or left screen edge)
@@ -4249,7 +4249,7 @@ gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4249 warnings. */ 4249 warnings. */
4250 w = (uintptr_t) FRAME_NATIVE_WINDOW (f); 4250 w = (uintptr_t) FRAME_NATIVE_WINDOW (f);
4251 store_in_alist (alistptr, Qwindow_id, 4251 store_in_alist (alistptr, Qwindow_id,
4252 make_formatted_string (buf, "%"pMu, w)); 4252 make_formatted_string (buf, "%"PRIuMAX, w));
4253#ifdef HAVE_X_WINDOWS 4253#ifdef HAVE_X_WINDOWS
4254#ifdef USE_X_TOOLKIT 4254#ifdef USE_X_TOOLKIT
4255 /* Tooltip frame may not have this widget. */ 4255 /* Tooltip frame may not have this widget. */
@@ -4257,7 +4257,7 @@ gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
4257#endif 4257#endif
4258 w = (uintptr_t) FRAME_OUTER_WINDOW (f); 4258 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
4259 store_in_alist (alistptr, Qouter_window_id, 4259 store_in_alist (alistptr, Qouter_window_id,
4260 make_formatted_string (buf, "%"pMu, w)); 4260 make_formatted_string (buf, "%"PRIuMAX, w));
4261#endif 4261#endif
4262 store_in_alist (alistptr, Qicon_name, f->icon_name); 4262 store_in_alist (alistptr, Qicon_name, f->icon_name);
4263 store_in_alist (alistptr, Qvisibility, 4263 store_in_alist (alistptr, Qvisibility,
diff --git a/src/gnutls.c b/src/gnutls.c
index 1afbb2bd4e5..267ba9aba35 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -2098,8 +2098,8 @@ gnutls_symmetric_aead (bool encrypting, gnutls_cipher_algorithm_t gca,
2098 SAFE_FREE (); 2098 SAFE_FREE ();
2099 return list2 (output, actual_iv); 2099 return list2 (output, actual_iv);
2100# else 2100# else
2101 printmax_t print_gca = gca; 2101 intmax_t print_gca = gca;
2102 error ("GnuTLS AEAD cipher %"pMd" is invalid or not found", print_gca); 2102 error ("GnuTLS AEAD cipher %"PRIdMAX" is invalid or not found", print_gca);
2103# endif 2103# endif
2104} 2104}
2105 2105
diff --git a/src/image.c b/src/image.c
index 6ead12166b6..b4b6c1bac1c 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9735,8 +9735,8 @@ gs_image_p (Lisp_Object object)
9735static bool 9735static bool
9736gs_load (struct frame *f, struct image *img) 9736gs_load (struct frame *f, struct image *img)
9737{ 9737{
9738 uprintmax_t printnum1, printnum2; 9738 uintmax_t printnum1, printnum2;
9739 char buffer[sizeof " " + INT_STRLEN_BOUND (printmax_t)]; 9739 char buffer[sizeof " " + 2 * INT_STRLEN_BOUND (intmax_t)];
9740 Lisp_Object window_and_pixmap_id = Qnil, loader, pt_height, pt_width; 9740 Lisp_Object window_and_pixmap_id = Qnil, loader, pt_height, pt_width;
9741 Lisp_Object frame; 9741 Lisp_Object frame;
9742 double in_width, in_height; 9742 double in_width, in_height;
@@ -9788,12 +9788,14 @@ gs_load (struct frame *f, struct image *img)
9788 printnum1 = FRAME_X_DRAWABLE (f); 9788 printnum1 = FRAME_X_DRAWABLE (f);
9789 printnum2 = img->pixmap; 9789 printnum2 = img->pixmap;
9790 window_and_pixmap_id 9790 window_and_pixmap_id
9791 = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2); 9791 = make_formatted_string (buffer, "%"PRIuMAX" %"PRIuMAX,
9792 printnum1, printnum2);
9792 9793
9793 printnum1 = FRAME_FOREGROUND_PIXEL (f); 9794 printnum1 = FRAME_FOREGROUND_PIXEL (f);
9794 printnum2 = FRAME_BACKGROUND_PIXEL (f); 9795 printnum2 = FRAME_BACKGROUND_PIXEL (f);
9795 pixel_colors 9796 pixel_colors
9796 = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2); 9797 = make_formatted_string (buffer, "%"PRIuMAX" %"PRIuMAX,
9798 printnum1, printnum2);
9797 9799
9798 XSETFRAME (frame, f); 9800 XSETFRAME (frame, f);
9799 loader = image_spec_value (img->spec, QCloader, NULL); 9801 loader = image_spec_value (img->spec, QCloader, NULL);
diff --git a/src/lisp.h b/src/lisp.h
index 1a1d8ee7e48..8acf63fe227 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -134,25 +134,6 @@ enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR };
134#endif 134#endif
135verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1); 135verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1);
136 136
137/* printmax_t and uprintmax_t are types for printing large integers.
138 These are the widest integers that are supported for printing.
139 pMd etc. are conversions for printing them.
140 On C99 hosts, there's no problem, as even the widest integers work.
141 Fall back on EMACS_INT on pre-C99 hosts. */
142#ifdef PRIdMAX
143typedef intmax_t printmax_t;
144typedef uintmax_t uprintmax_t;
145# define pMd PRIdMAX
146# define pMu PRIuMAX
147# define pMx PRIxMAX
148#else
149typedef EMACS_INT printmax_t;
150typedef EMACS_UINT uprintmax_t;
151# define pMd pI"d"
152# define pMu pI"u"
153# define pMx pI"x"
154#endif
155
156/* Use pD to format ptrdiff_t values, which suffice for indexes into 137/* Use pD to format ptrdiff_t values, which suffice for indexes into
157 buffers and strings. Emacs never allocates objects larger than 138 buffers and strings. Emacs never allocates objects larger than
158 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction. 139 PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
diff --git a/src/print.c b/src/print.c
index 406abbf4a3f..dc44b1e89e0 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1017,8 +1017,8 @@ float_to_string (char *buf, double data)
1017 if (isnan (data)) 1017 if (isnan (data))
1018 { 1018 {
1019 union ieee754_double u = { .d = data }; 1019 union ieee754_double u = { .d = data };
1020 uprintmax_t hi = u.ieee_nan.mantissa0; 1020 uintmax_t hi = u.ieee_nan.mantissa0;
1021 return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative], 1021 return sprintf (buf, &"-%"PRIuMAX".0e+NaN"[!u.ieee_nan.negative],
1022 (hi << 31 << 1) + u.ieee_nan.mantissa1); 1022 (hi << 31 << 1) + u.ieee_nan.mantissa1);
1023 } 1023 }
1024#endif 1024#endif
@@ -1811,9 +1811,9 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
1811 1811
1812 /* In theory this assignment could lose info on pre-C99 1812 /* In theory this assignment could lose info on pre-C99
1813 hosts, but in practice it doesn't. */ 1813 hosts, but in practice it doesn't. */
1814 uprintmax_t up = ui; 1814 uintmax_t up = ui;
1815 1815
1816 int len = sprintf (buf, "at 0x%"pMx, up); 1816 int len = sprintf (buf, "at 0x%"PRIxMAX, up);
1817 strout (buf, len, len, printcharfun); 1817 strout (buf, len, len, printcharfun);
1818 } 1818 }
1819 else 1819 else
@@ -1841,9 +1841,9 @@ static void
1841print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) 1841print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1842{ 1842{
1843 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT), 1843 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
1844 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t), 1844 max (sizeof " . #" + INT_STRLEN_BOUND (intmax_t),
1845 max ((sizeof "at 0x" 1845 max ((sizeof "at 0x"
1846 + (sizeof (uprintmax_t) * CHAR_BIT + 4 - 1) / 4), 1846 + (sizeof (uintmax_t) * CHAR_BIT + 4 - 1) / 4),
1847 40)))]; 1847 40)))];
1848 current_thread->stack_top = buf; 1848 current_thread->stack_top = buf;
1849 maybe_quit (); 1849 maybe_quit ();
@@ -2096,11 +2096,11 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2096 2096
2097 /* Negative values of print-length are invalid in CL. 2097 /* Negative values of print-length are invalid in CL.
2098 Treat them like nil, as CMUCL does. */ 2098 Treat them like nil, as CMUCL does. */
2099 printmax_t print_length = (FIXNATP (Vprint_length) 2099 intmax_t print_length = (FIXNATP (Vprint_length)
2100 ? XFIXNAT (Vprint_length) 2100 ? XFIXNAT (Vprint_length)
2101 : TYPE_MAXIMUM (printmax_t)); 2101 : INTMAX_MAX);
2102 2102
2103 printmax_t i = 0; 2103 intmax_t i = 0;
2104 while (CONSP (obj)) 2104 while (CONSP (obj))
2105 { 2105 {
2106 /* Detect circular list. */ 2106 /* Detect circular list. */
@@ -2109,7 +2109,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
2109 /* Simple but incomplete way. */ 2109 /* Simple but incomplete way. */
2110 if (i != 0 && EQ (obj, halftail)) 2110 if (i != 0 && EQ (obj, halftail))
2111 { 2111 {
2112 int len = sprintf (buf, " . #%"pMd, i / 2); 2112 int len = sprintf (buf, " . #%"PRIdMAX, i >> 1);
2113 strout (buf, len, len, printcharfun); 2113 strout (buf, len, len, printcharfun);
2114 goto end_of_list; 2114 goto end_of_list;
2115 } 2115 }
diff --git a/src/process.c b/src/process.c
index cab390c10c6..5f552675db6 100644
--- a/src/process.c
+++ b/src/process.c
@@ -888,13 +888,13 @@ make_process (Lisp_Object name)
888 /* If name is already in use, modify it until it is unused. */ 888 /* If name is already in use, modify it until it is unused. */
889 889
890 Lisp_Object name1 = name; 890 Lisp_Object name1 = name;
891 for (printmax_t i = 1; ; i++) 891 for (intmax_t i = 1; ; i++)
892 { 892 {
893 Lisp_Object tem = Fget_process (name1); 893 Lisp_Object tem = Fget_process (name1);
894 if (NILP (tem)) 894 if (NILP (tem))
895 break; 895 break;
896 char const suffix_fmt[] = "<%"pMd">"; 896 char const suffix_fmt[] = "<%"PRIdMAX">";
897 char suffix[sizeof suffix_fmt + INT_STRLEN_BOUND (printmax_t)]; 897 char suffix[sizeof suffix_fmt + INT_STRLEN_BOUND (i)];
898 AUTO_STRING_WITH_LEN (lsuffix, suffix, sprintf (suffix, suffix_fmt, i)); 898 AUTO_STRING_WITH_LEN (lsuffix, suffix, sprintf (suffix, suffix_fmt, i));
899 name1 = concat2 (name, lsuffix); 899 name1 = concat2 (name, lsuffix);
900 } 900 }
diff --git a/src/sysdep.c b/src/sysdep.c
index 48eebb594f7..c7d7eefc2ab 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3269,7 +3269,7 @@ system_process_attributes (Lisp_Object pid)
3269 char *cmdline = NULL; 3269 char *cmdline = NULL;
3270 ptrdiff_t cmdline_size; 3270 ptrdiff_t cmdline_size;
3271 char c; 3271 char c;
3272 printmax_t proc_id; 3272 intmax_t proc_id;
3273 int ppid, pgrp, sess, tty, tpgid, thcount; 3273 int ppid, pgrp, sess, tty, tpgid, thcount;
3274 uid_t uid; 3274 uid_t uid;
3275 gid_t gid; 3275 gid_t gid;
@@ -3284,7 +3284,7 @@ system_process_attributes (Lisp_Object pid)
3284 3284
3285 CHECK_NUMBER (pid); 3285 CHECK_NUMBER (pid);
3286 CONS_TO_INTEGER (pid, pid_t, proc_id); 3286 CONS_TO_INTEGER (pid, pid_t, proc_id);
3287 sprintf (procfn, "/proc/%"pMd, proc_id); 3287 sprintf (procfn, "/proc/%"PRIdMAX, proc_id);
3288 if (stat (procfn, &st) < 0) 3288 if (stat (procfn, &st) < 0)
3289 return attrs; 3289 return attrs;
3290 3290
@@ -3505,7 +3505,7 @@ system_process_attributes (Lisp_Object pid)
3505 struct psinfo pinfo; 3505 struct psinfo pinfo;
3506 int fd; 3506 int fd;
3507 ssize_t nread; 3507 ssize_t nread;
3508 printmax_t proc_id; 3508 intmax_t proc_id;
3509 uid_t uid; 3509 uid_t uid;
3510 gid_t gid; 3510 gid_t gid;
3511 Lisp_Object attrs = Qnil; 3511 Lisp_Object attrs = Qnil;
@@ -3514,7 +3514,7 @@ system_process_attributes (Lisp_Object pid)
3514 3514
3515 CHECK_NUMBER (pid); 3515 CHECK_NUMBER (pid);
3516 CONS_TO_INTEGER (pid, pid_t, proc_id); 3516 CONS_TO_INTEGER (pid, pid_t, proc_id);
3517 sprintf (procfn, "/proc/%"pMd, proc_id); 3517 sprintf (procfn, "/proc/%"PRIdMAX, proc_id);
3518 if (stat (procfn, &st) < 0) 3518 if (stat (procfn, &st) < 0)
3519 return attrs; 3519 return attrs;
3520 3520
diff --git a/src/timefns.c b/src/timefns.c
index 7b5af6a5d24..3b7ed460222 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1573,9 +1573,9 @@ without consideration for daylight saving time. */)
1573 static char const mon_name[][4] = 1573 static char const mon_name[][4] =
1574 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 1574 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1575 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 1575 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
1576 printmax_t year_base = TM_YEAR_BASE; 1576 intmax_t year_base = TM_YEAR_BASE;
1577 char buf[sizeof "Mon Apr 30 12:49:17 " + INT_STRLEN_BOUND (int) + 1]; 1577 char buf[sizeof "Mon Apr 30 12:49:17 " + INT_STRLEN_BOUND (int) + 1];
1578 int len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"pMd, 1578 int len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"PRIdMAX,
1579 wday_name[tm.tm_wday], mon_name[tm.tm_mon], tm.tm_mday, 1579 wday_name[tm.tm_wday], mon_name[tm.tm_mon], tm.tm_mday,
1580 tm.tm_hour, tm.tm_min, tm.tm_sec, 1580 tm.tm_hour, tm.tm_min, tm.tm_sec,
1581 tm.tm_year + year_base); 1581 tm.tm_year + year_base);
diff --git a/src/unexelf.c b/src/unexelf.c
index 6d19bf1fb9f..79b3d444639 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -187,7 +187,8 @@ verify ((! TYPE_SIGNED (ElfW (Half))
187 && TYPE_MAXIMUM (ElfW (Half)) <= PTRDIFF_MAX); 187 && TYPE_MAXIMUM (ElfW (Half)) <= PTRDIFF_MAX);
188 188
189#ifdef UNEXELF_DEBUG 189#ifdef UNEXELF_DEBUG
190# define DEBUG_LOG(expr) fprintf (stderr, #expr " 0x%jx\n", (uintmax_t) (expr)) 190# define DEBUG_LOG(expr) fprintf (stderr, #expr " 0x%"PRIxMAX"\n", \
191 (uintmax_t) (expr))
191#endif 192#endif
192 193
193/* Get the address of a particular section or program header entry, 194/* Get the address of a particular section or program header entry,
diff --git a/src/xdisp.c b/src/xdisp.c
index 5fb690e746d..75cc97df1c0 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10540,7 +10540,7 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte)
10540 if (nlflag) 10540 if (nlflag)
10541 { 10541 {
10542 ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte; 10542 ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte;
10543 printmax_t dups; 10543 intmax_t dups;
10544 10544
10545 /* Since we call del_range_both passing false for PREPARE, 10545 /* Since we call del_range_both passing false for PREPARE,
10546 we aren't prepared to run modification hooks (we could 10546 we aren't prepared to run modification hooks (we could
@@ -10572,11 +10572,12 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte)
10572 if (dups > 1) 10572 if (dups > 1)
10573 { 10573 {
10574 char dupstr[sizeof " [ times]" 10574 char dupstr[sizeof " [ times]"
10575 + INT_STRLEN_BOUND (printmax_t)]; 10575 + INT_STRLEN_BOUND (dups)];
10576 10576
10577 /* If you change this format, don't forget to also 10577 /* If you change this format, don't forget to also
10578 change message_log_check_duplicate. */ 10578 change message_log_check_duplicate. */
10579 int duplen = sprintf (dupstr, " [%"pMd" times]", dups); 10579 int duplen = sprintf (dupstr, " [%"PRIdMAX" times]",
10580 dups);
10580 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); 10581 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1);
10581 insert_1_both (dupstr, duplen, duplen, 10582 insert_1_both (dupstr, duplen, duplen,
10582 true, false, true); 10583 true, false, true);
diff --git a/src/xselect.c b/src/xselect.c
index 5f0bb44cc9a..c5085f7e7b4 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -63,13 +63,13 @@ static void lisp_data_to_selection_data (struct x_display_info *, Lisp_Object,
63 63
64#ifdef TRACE_SELECTION 64#ifdef TRACE_SELECTION
65#define TRACE0(fmt) \ 65#define TRACE0(fmt) \
66 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid ()) 66 fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid ())
67#define TRACE1(fmt, a0) \ 67#define TRACE1(fmt, a0) \
68 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0) 68 fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0)
69#define TRACE2(fmt, a0, a1) \ 69#define TRACE2(fmt, a0, a1) \
70 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1) 70 fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0, a1)
71#define TRACE3(fmt, a0, a1, a2) \ 71#define TRACE3(fmt, a0, a1, a2) \
72 fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1, a2) 72 fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0, a1, a2)
73#else 73#else
74#define TRACE0(fmt) (void) 0 74#define TRACE0(fmt) (void) 0
75#define TRACE1(fmt, a0) (void) 0 75#define TRACE1(fmt, a0) (void) 0