diff src/doprnt.c @ 4287:89e64783d068

[xemacs-hg @ 2007-11-27 13:51:03 by aidan] Merge a bugfix to some previously merged SXEmacs code; thank you Sebastian Freundt for the code, and Hans de Graaff for the report.
author aidan
date Tue, 27 Nov 2007 13:51:10 +0000
parents 4ca1ef2bdb6a
children d9eb5ea14f65
line wrap: on
line diff
--- a/src/doprnt.c	Mon Nov 26 22:51:07 2007 +0000
+++ b/src/doprnt.c	Tue Nov 27 13:51:10 2007 +0000
@@ -776,9 +776,21 @@
 #endif /* HAVE_BIGFLOAT */
 	  else
 	    {
-	      Ascbyte *text_to_print = alloca_array (char, 350);
+	      Ascbyte *text_to_print;
 	      Ascbyte constructed_spec[100];
 	      Ascbyte *p = constructed_spec;
+              int alloca_sz = 350;
+              int min = spec->minwidth, prec = spec->precision;
+
+              if (prec < 0)
+                prec = 0;
+              if (min < 0)
+                min = 0;
+
+              if (32+min+prec > alloca_sz)
+                alloca_sz = 32 + min + prec;
+
+              text_to_print = alloca_array(char, alloca_sz);
 
 	      /* Mostly reconstruct the spec and use sprintf() to
 		 format the string. */