aboutsummaryrefslogtreecommitdiffstats
path: root/src/print.c
diff options
context:
space:
mode:
authorPaul Eggert2011-04-18 17:34:42 -0700
committerPaul Eggert2011-04-18 17:34:42 -0700
commitc2982e87d382f0b5c00a65e63716c2b43d342881 (patch)
treeb8f155c52150e3cc85a26299812d139efd86231e /src/print.c
parent5e073ec7384c432e42a8affeeb6d6906588f2af9 (diff)
downloademacs-c2982e87d382f0b5c00a65e63716c2b43d342881.tar.gz
emacs-c2982e87d382f0b5c00a65e63716c2b43d342881.zip
Replace pEd with more-general pI, and fix some printf arg casts.
* lisp.h (pI): New macro, generalizing old pEd macro to other conversion specifiers. For example, use "...%"pI"d..." rather than "...%"pEd"...". (pEd): Remove. All uses replaced with similar uses of pI. * src/m/amdx86-64.h, src/m/ia64.h, src/m/ibms390x.h: Likewise. * alloc.c (check_pure_size): Don't overflow by converting size to int. * bidi.c (bidi_dump_cached_states): Use pI to avoid cast. * data.c (Fnumber_to_string): Use pI instead of if-then-else-abort. * dbusbind.c (xd_append_arg): Use pI to avoid cast. (Fdbus_method_return_internal, Fdbus_method_error_internal): Likewise. * font.c (font_unparse_xlfd): Avoid potential buffer overrun on 64-bit hosts. (font_unparse_xlfd, font_unparse_fcname): Use pI to avoid casts. * keyboard.c (record_char, modify_event_symbol): Use pI to avoid casts. * print.c (safe_debug_print, print_object): Likewise. (print_object): Don't overflow by converting EMACS_INT or EMACS_UINT to int. Use pI instead of if-then-else-abort. Use %p to avoid casts. * process.c (Fmake_network_process): Use pI to avoid cast. * region-cache.c (pp_cache): Likewise. * xdisp.c (decode_mode_spec): Likewise. * xrdb.c (x_load_resources) [USE_MOTIF]: Use pI to avoid undefined behavior on 64-bit hosts with printf arg. * xselect.c (x_queue_event): Use %p to avoid casts. (x_stop_queuing_selection_requests): Likewise. (x_get_window_property): Don't truncate byte count to an 'int' when tracing.
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/print.c b/src/print.c
index 6a331cb11f2..d837a533818 100644
--- a/src/print.c
+++ b/src/print.c
@@ -808,10 +808,9 @@ safe_debug_print (Lisp_Object arg)
808 if (valid > 0) 808 if (valid > 0)
809 debug_print (arg); 809 debug_print (arg);
810 else 810 else
811 fprintf (stderr, "#<%s_LISP_OBJECT 0x%08lx>\r\n", 811 fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n",
812 !valid ? "INVALID" : "SOME", 812 !valid ? "INVALID" : "SOME",
813 (unsigned long) XHASH (arg) 813 XHASH (arg));
814 );
815} 814}
816 815
817 816
@@ -1338,11 +1337,11 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1338 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); 1337 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1339 if (INTEGERP (num)) 1338 if (INTEGERP (num))
1340 { 1339 {
1341 int n = XINT (num); 1340 EMACS_INT n = XINT (num);
1342 if (n < 0) 1341 if (n < 0)
1343 { /* Add a prefix #n= if OBJ has not yet been printed; 1342 { /* Add a prefix #n= if OBJ has not yet been printed;
1344 that is, its status field is nil. */ 1343 that is, its status field is nil. */
1345 sprintf (buf, "#%d=", -n); 1344 sprintf (buf, "#%"pI"d=", -n);
1346 strout (buf, -1, -1, printcharfun); 1345 strout (buf, -1, -1, printcharfun);
1347 /* OBJ is going to be printed. Remember that fact. */ 1346 /* OBJ is going to be printed. Remember that fact. */
1348 Fputhash (obj, make_number (- n), Vprint_number_table); 1347 Fputhash (obj, make_number (- n), Vprint_number_table);
@@ -1350,7 +1349,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1350 else 1349 else
1351 { 1350 {
1352 /* Just print #n# if OBJ has already been printed. */ 1351 /* Just print #n# if OBJ has already been printed. */
1353 sprintf (buf, "#%d#", n); 1352 sprintf (buf, "#%"pI"d#", n);
1354 strout (buf, -1, -1, printcharfun); 1353 strout (buf, -1, -1, printcharfun);
1355 return; 1354 return;
1356 } 1355 }
@@ -1363,12 +1362,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1363 switch (XTYPE (obj)) 1362 switch (XTYPE (obj))
1364 { 1363 {
1365 case_Lisp_Int: 1364 case_Lisp_Int:
1366 if (sizeof (int) == sizeof (EMACS_INT)) 1365 sprintf (buf, "%"pI"d", XINT (obj));
1367 sprintf (buf, "%d", (int) XINT (obj));
1368 else if (sizeof (long) == sizeof (EMACS_INT))
1369 sprintf (buf, "%ld", (long) XINT (obj));
1370 else
1371 abort ();
1372 strout (buf, -1, -1, printcharfun); 1366 strout (buf, -1, -1, printcharfun);
1373 break; 1367 break;
1374 1368
@@ -1701,7 +1695,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1701 1695
1702 PRINTCHAR ('#'); 1696 PRINTCHAR ('#');
1703 PRINTCHAR ('&'); 1697 PRINTCHAR ('&');
1704 sprintf (buf, "%ld", (long) XBOOL_VECTOR (obj)->size); 1698 sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size);
1705 strout (buf, -1, -1, printcharfun); 1699 strout (buf, -1, -1, printcharfun);
1706 PRINTCHAR ('\"'); 1700 PRINTCHAR ('\"');
1707 1701
@@ -1754,7 +1748,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1754 else if (WINDOWP (obj)) 1748 else if (WINDOWP (obj))
1755 { 1749 {
1756 strout ("#<window ", -1, -1, printcharfun); 1750 strout ("#<window ", -1, -1, printcharfun);
1757 sprintf (buf, "%ld", (long) XFASTINT (XWINDOW (obj)->sequence_number)); 1751 sprintf (buf, "%"pI"d", XFASTINT (XWINDOW (obj)->sequence_number));
1758 strout (buf, -1, -1, printcharfun); 1752 strout (buf, -1, -1, printcharfun);
1759 if (!NILP (XWINDOW (obj)->buffer)) 1753 if (!NILP (XWINDOW (obj)->buffer))
1760 { 1754 {
@@ -1881,7 +1875,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1881 ? "#<frame " : "#<dead frame "), 1875 ? "#<frame " : "#<dead frame "),
1882 -1, -1, printcharfun); 1876 -1, -1, printcharfun);
1883 print_string (XFRAME (obj)->name, printcharfun); 1877 print_string (XFRAME (obj)->name, printcharfun);
1884 sprintf (buf, " 0x%lx", (unsigned long) (XFRAME (obj))); 1878 sprintf (buf, " %p", XFRAME (obj));
1885 strout (buf, -1, -1, printcharfun); 1879 strout (buf, -1, -1, printcharfun);
1886 PRINTCHAR ('>'); 1880 PRINTCHAR ('>');
1887 } 1881 }
@@ -1978,7 +1972,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1978 strout ("in no buffer", -1, -1, printcharfun); 1972 strout ("in no buffer", -1, -1, printcharfun);
1979 else 1973 else
1980 { 1974 {
1981 sprintf (buf, "at %ld", (long)marker_position (obj)); 1975 sprintf (buf, "at %"pI"d", marker_position (obj));
1982 strout (buf, -1, -1, printcharfun); 1976 strout (buf, -1, -1, printcharfun);
1983 strout (" in ", -1, -1, printcharfun); 1977 strout (" in ", -1, -1, printcharfun);
1984 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun); 1978 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
@@ -1992,9 +1986,9 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
1992 strout ("in no buffer", -1, -1, printcharfun); 1986 strout ("in no buffer", -1, -1, printcharfun);
1993 else 1987 else
1994 { 1988 {
1995 sprintf (buf, "from %ld to %ld in ", 1989 sprintf (buf, "from %"pI"d to %"pI"d in ",
1996 (long)marker_position (OVERLAY_START (obj)), 1990 marker_position (OVERLAY_START (obj)),
1997 (long)marker_position (OVERLAY_END (obj))); 1991 marker_position (OVERLAY_END (obj)));
1998 strout (buf, -1, -1, printcharfun); 1992 strout (buf, -1, -1, printcharfun);
1999 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name), 1993 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
2000 printcharfun); 1994 printcharfun);
@@ -2010,8 +2004,8 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2010 2004
2011 case Lisp_Misc_Save_Value: 2005 case Lisp_Misc_Save_Value:
2012 strout ("#<save_value ", -1, -1, printcharfun); 2006 strout ("#<save_value ", -1, -1, printcharfun);
2013 sprintf(buf, "ptr=0x%08lx int=%d", 2007 sprintf(buf, "ptr=%08p int=%d",
2014 (unsigned long) XSAVE_VALUE (obj)->pointer, 2008 XSAVE_VALUE (obj)->pointer,
2015 XSAVE_VALUE (obj)->integer); 2009 XSAVE_VALUE (obj)->integer);
2016 strout (buf, -1, -1, printcharfun); 2010 strout (buf, -1, -1, printcharfun);
2017 PRINTCHAR ('>'); 2011 PRINTCHAR ('>');
@@ -2031,7 +2025,7 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag
2031 if (MISCP (obj)) 2025 if (MISCP (obj))
2032 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); 2026 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2033 else if (VECTORLIKEP (obj)) 2027 else if (VECTORLIKEP (obj))
2034 sprintf (buf, "(PVEC 0x%08x)", (int) XVECTOR (obj)->size); 2028 sprintf (buf, "(PVEC 0x%08lx)", (unsigned long) XVECTOR (obj)->size);
2035 else 2029 else
2036 sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); 2030 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2037 strout (buf, -1, -1, printcharfun); 2031 strout (buf, -1, -1, printcharfun);