]> granicus.if.org Git - php/commitdiff
Fixed bug #22207 (e notation in *printf would be missing a 0 when there is
authorIlia Alshanetsky <iliaa@php.net>
Thu, 13 Feb 2003 17:25:31 +0000 (17:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 13 Feb 2003 17:25:31 +0000 (17:25 +0000)
no exponent).
Added a test case for the bug.

ext/standard/formatted_print.c
ext/standard/tests/strings/bug22207.phpt [new file with mode: 0644]

index d5bd95c4b79d93416b016092d4b1112c35820392..b53d5e3072faa774c06ad15fc9bbfafffe0ae39c 100644 (file)
@@ -359,8 +359,12 @@ php_sprintf_appenddouble(char **buffer, int *pos,
                numbuf[i++] = fmt;
                exp_p = php_convert_to_decimal(decpt, 0, &dec2, &sign, 0);
                numbuf[i++] = sign ? '-' : '+';
-               while (*exp_p) {
-                       numbuf[i++] = *(exp_p++);
+               if (*exp_p) { 
+                       while (*exp_p) {
+                               numbuf[i++] = *(exp_p++);
+                       }
+               } else {
+                       numbuf[i++] = '0';
                }
        } else {
                numbuf[i++] = cvt[j++];
diff --git a/ext/standard/tests/strings/bug22207.phpt b/ext/standard/tests/strings/bug22207.phpt
new file mode 100644 (file)
index 0000000..1623fb8
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #22207 (missing 0 when using the e notation in *printf functions)
+--FILE--
+<?php
+       printf("%10.5e\n", 1.1); 
+       var_dump(sprintf("%10.5e\n", 1.1));
+?>
+--EXPECT--
+1.1000e+0
+string(17) "       1.1000e+0
+"