Sophie

Sophie

distrib > Mandriva > 2007.1 > x86_64 > by-pkgid > 6779cf6e61ddc030d6b05908a8df8cda > files > 27

emacs-21.4-26.4mdv2007.1.src.rpm

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.

Index: src/editfns.c
================================================================================
--- src/editfns.c
+++ src/editfns.c
@@ -3209,8 +3209,10 @@ Use %% to put a single % into the output
 	      precision = 10 * precision + *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");
@@ -3266,7 +3268,7 @@ Use %% to put a single % into the output
 		  && *format != 'i' && *format != 'X' && *format != 'c')
 		error ("Invalid format operation %%%c", *format);
 
-	    thissize = 30;
+	    thissize = 30 + (precision > 0 ? precision : 0);
 	    if (*format == 'c'
 		&& (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
 		    || XINT (args[n]) == 0))
@@ -3415,7 +3417,22 @@ Use %% to put a single % into the output
 	      this_format[format - this_format_start] = 0;
 
 	      if (INTEGERP (args[n]))
-		sprintf (p, this_format, XINT (args[n]));
+		{
+		  if (format[-1] == 'c')
+		    sprintf (p, this_format, (int) XINT (args[n]));
+		  else
+		    {
+		      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;
+			}
+		      sprintf (p, this_format, XINT (args[n]));
+		    }
+		}
 	      else
 		sprintf (p, this_format, XFLOAT_DATA (args[n]));