Re: Segfault patch

From: Date: Sat, 15 Apr 2000 11:04:34 +0000
Subject: Re: Segfault patch
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-17925@lists.php.net to get a copy of this message
Jon, Isn't DBL_MAX_10_EXP much too large? There might be some better idea to calculate the maximum length of the resulting string. Andi At 06:12 PM 4/14/00 +0200, Jon Forsberg wrote:
PHP 4.0RC1 (and 3.0.15) segfaults when formatting very big numbers with number_format: $a="1E+32"; print(number_format($a, 2, ",", ".")); Here 1E+32 and anything over makes PHP segfault. The fix:
--- ext/standard/math.c.orig    Sun Mar 12 18:18:21 2000
+++ ext/standard/math.c Fri Apr 14 17:26:25 2000 @@ -25,6 +25,7 @@ #include "phpmath.h" #include <math.h> +#include <float.h> #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -611,7 +612,7 @@
                d = -d;
        }
        dec = MAX(0,dec);
-       tmpbuf = (char *) emalloc(32+dec);
+       tmpbuf = (char *) emalloc(1 + DBL_MAX_10_EXP + 1 + dec + 1);
        tmplen=sprintf(tmpbuf,"%.*f",dec,d);
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
--- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.dev (#17925) next »