summaryrefslogtreecommitdiff
blob: 851bcb91f4d98db2fe452efe04cfda09172fab8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
2007-11-15  Andreas Schwab  <schwab@suse.de>

	* editfns.c (Fformat): Correctly format EMACS_INT values.  Also
	take precision into account when formatting an integer.

--- src/editfns.c	8 Aug 2007 07:49:19 -0000	1.439.2.3
+++ src/editfns.c	16 Nov 2007 00:18:55 -0000	1.439.2.8
@@ -3543,8 +3543,10 @@ usage: (format STRING &rest OBJECTS)  */
 	      precision[n+1] = 10 * precision[n+1] + *format - '0';
 	  }
 
-	if (format - this_format_start + 1 > longest_format)
-	  longest_format = format - this_format_start + 1;
+	/* Extra +1 for 'l' that we may need to insert into the
+	   format.  */
+	if (format - this_format_start + 2 > longest_format)
+	  longest_format = format - this_format_start + 2;
 
 	if (format == end)
 	  error ("Format string ends in middle of format specifier");
@@ -3605,7 +3607,7 @@ usage: (format STRING &rest OBJECTS)  */
 		  && *format != 'i' && *format != 'X' && *format != 'c')
 		error ("Invalid format operation %%%c", *format);
 
-	    thissize = 30;
+	    thissize = 30 + (precision[n] > 0 ? precision[n] : 0);
 	    if (*format == 'c')
 	      {
 		if (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
@@ -3803,23 +3805,35 @@ usage: (format STRING &rest OBJECTS)  */
 		     format - this_format_start);
 	      this_format[format - this_format_start] = 0;
 
-	      if (INTEGERP (args[n]))
+	      if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g')
+		sprintf (p, this_format, XFLOAT_DATA (args[n]));
+	      else
 		{
-		  if (format[-1] == 'd')
-		    sprintf (p, this_format, XINT (args[n]));
-		  /* Don't sign-extend for octal or hex printing.  */
+		  if (sizeof (EMACS_INT) > sizeof (int))
+		    {
+		      /* Insert 'l' before format spec.  */
+		      this_format[format - this_format_start]
+			= this_format[format - this_format_start - 1];
+		      this_format[format - this_format_start - 1] = 'l';
+		      this_format[format - this_format_start + 1] = 0;
+		    }
+
+		  if (INTEGERP (args[n]))
+		    {
+		      if (format[-1] == 'd')
+			sprintf (p, this_format, XINT (args[n]));
+		      /* Don't sign-extend for octal or hex printing.  */
+		      else
+			sprintf (p, this_format, XUINT (args[n]));
+		    }
+		  else if (format[-1] == 'd')
+		    /* Maybe we should use "%1.0f" instead so it also works
+		       for values larger than MAXINT.  */
+		    sprintf (p, this_format, (EMACS_INT) XFLOAT_DATA (args[n]));
 		  else
-		    sprintf (p, this_format, XUINT (args[n]));
+		    /* Don't sign-extend for octal or hex printing.  */
+		    sprintf (p, this_format, (EMACS_UINT) XFLOAT_DATA (args[n]));
 		}
-	      else if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g')
-		sprintf (p, this_format, XFLOAT_DATA (args[n]));
-	      else if (format[-1] == 'd')
-		/* Maybe we should use "%1.0f" instead so it also works
-		   for values larger than MAXINT.  */
-		sprintf (p, this_format, (EMACS_INT) XFLOAT_DATA (args[n]));
-	      else
-		/* Don't sign-extend for octal or hex printing.  */
-		sprintf (p, this_format, (EMACS_UINT) XFLOAT_DATA (args[n]));
 
 	      if (p > buf
 		  && multibyte