changeset 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 691b934b7b83
children 9eb558ffe8ff
files src/ChangeLog src/doprnt.c tests/ChangeLog tests/automated/lisp-tests.el
diffstat 4 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Nov 26 22:51:07 2007 +0000
+++ b/src/ChangeLog	Tue Nov 27 13:51:10 2007 +0000
@@ -1,3 +1,12 @@
+2007-11-26  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* doprnt.c: 
+	Default to a buffer size of 350 for the sprintf call, but increase
+	it if the precision and minwidth indicate that it should be
+	bigger. Issue reported by Hans de Graaff; bug originally fixed by
+	Sebastian Freundt in SXEmacs following the change I merged on
+	2006-11-28. Forks have their disadvantages. 
+
 2007-11-11  Mats Lidell  <matsl@xemacs.org>
 
 	* events.h: Based on SXEmacs patch. Support for mouse button 6 to
--- 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. */
--- a/tests/ChangeLog	Mon Nov 26 22:51:07 2007 +0000
+++ b/tests/ChangeLog	Tue Nov 27 13:51:10 2007 +0000
@@ -1,3 +1,9 @@
+2007-11-26  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* automated/lisp-tests.el:
+	Check that a couple of previously problematic calls to #'format
+	succeed.
+
 2007-09-30  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* automated/os-tests.el: Suppress `executable-find' lossage.
--- a/tests/automated/lisp-tests.el	Mon Nov 26 22:51:07 2007 +0000
+++ b/tests/automated/lisp-tests.el	Tue Nov 27 13:51:10 2007 +0000
@@ -1279,6 +1279,10 @@
 (Assert (= (read (format "%d"  most-negative-fixnum)) most-negative-fixnum))
 (Assert (= (read (format "%ld" most-negative-fixnum)) most-negative-fixnum))
 
+;; These used to crash. 
+(Assert (eql (read (format "%f" 1.2e+302)) 1.2e+302))
+(Assert (eql (read (format "%.1000d" 1)) 1))
+
 ;;; "%u" is undocumented, and Emacs Lisp has no unsigned type.
 ;;; What to do if "%u" is used with a negative number?
 ;;; For non-bignum XEmacsen, the most reasonable thing seems to be to print an