]> granicus.if.org Git - php/commitdiff
Fix text output of numbers with absolute exponent greater than or equal 80.
authorMarcus Boerger <helly@php.net>
Thu, 17 Jul 2003 21:26:25 +0000 (21:26 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 17 Jul 2003 21:26:25 +0000 (21:26 +0000)
#
# Probably not last conclusion on wisdom. But i looked up current apache
# sources and they have the same error and so this must do the trick.
#

main/snprintf.c

index 71fb78f9d1ec38e34e89c3578796a6bfaa7858d3..d2cd7d967439c52f8081425a039bcda4bc96e034 100644 (file)
@@ -152,6 +152,8 @@ ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
        return (p);
 }
 
+/* If you change this value then also change bug24640.phpt.
+ */
 #define        NDIG    80
 
 
@@ -291,6 +293,7 @@ char *
 ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf)
 {
        register int r2;
+       int mvl;
        double fi, fj;
        register char *p, *p1;
 
@@ -310,9 +313,16 @@ ap_php_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf)
         */
        if (fi != 0) {
                p1 = &buf[NDIG];
-               while (p1 > &buf[0] && fi != 0) {
+               while (fi != 0) {
                        fj = modf(fi / 10, &fi);
-                       *--p1 = (int) ((fj + .03) * 10) + '0';
+                       if (p1 > &buf[0]) {
+                               *--p1 = (int) ((fj + .03) * 10) + '0';
+                       } else {
+                               mvl = NDIG - ndigits;
+                               memmove(&buf[mvl], &buf[0], NDIG-mvl-1);
+                               p1 += mvl;
+                               *--p1 = (int) ((fj + .03) * 10) + '0';
+                       }
                        r2++;
                }
                while (p1 < &buf[NDIG])