]> granicus.if.org Git - php/commitdiff
Fix bug #66179
authorAndrea Faulds <ajf@ajf.me>
Fri, 18 Dec 2015 19:29:35 +0000 (19:29 +0000)
committerAndrea Faulds <ajf@ajf.me>
Fri, 18 Dec 2015 19:31:21 +0000 (19:31 +0000)
This also fixes ext/standard/tests/general_functions/var_export-locale.phpt
to actually run the floating-point section.

NEWS
ext/standard/tests/general_functions/var_export-locale.phpt
ext/standard/tests/general_functions/var_export_basic1.phpt
ext/standard/tests/general_functions/var_export_basic3.phpt
ext/standard/tests/general_functions/var_export_bug66179.phpt [new file with mode: 0644]
ext/standard/var.c
tests/lang/bug24640.phpt

diff --git a/NEWS b/NEWS
index 131777052dd339c37e6d339a2b66d20007021cfd..baca4f29e3d6cf53a3602300f731eecb82c95ccc 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ PHP                                                                        NEWS
   . Fixed bug #71154 (Incorrect HT iterator invalidation causes iterator reuse).
     (Nikita)
   . Fixed bug #52355 (Negating zero does not produce negative zero). (Andrea)
+  . Fixed bug #66179 (var_export() exports float as integer). (Andrea)
 
 . CURL:
   . Fixed bug #71144 (Sementation fault when using cURL with ZTS).
index 1cadb4aa55d2891d514dc5ed07ed58676020738c..47dfcbb3ee3b503cbd70ab55e277b70477758ef1 100644 (file)
@@ -30,12 +30,12 @@ $valid_ints = array(
                 '0x12ab',
                 '0Xfff',
                 '0XFA',
-                -0x80000000, // max negative integer as hexadecimal
+                -0x7fffffff - 1, // max negative integer as hexadecimal
                 '0x7fffffff',  // max positive integer as hexadecimal
                 0x7FFFFFFF,  // max positive integer as hexadecimal
                 '0123',        // integer as octal
                 01,       // should be quivalent to octal 1
-                -020000000000, // max negative integer as octal
+                -017777777777 - 1, // max negative integer as octal
                 017777777777,  // max positive integer as octal
                );
 $counter = 1;
@@ -79,12 +79,12 @@ $counter++;
 echo "*** Testing var_export() with valid float values ***\n";
 // different valid  float vlaues 
 $valid_floats = array(
-  -2147483649, // float value
-  2147483648,  // float value
-  -0x80000001, // float value, beyond max negative int
-  0x800000001, // float value, beyond max positive int
-  020000000001, // float value, beyond max positive int
-  -020000000001, // float value, beyond max negative int
+  (float)-2147483649, // float value
+  (float)2147483648,  // float value
+  (float)-0x80000001, // float value, beyond max negative int
+  (float)0x800000001, // float value, beyond max positive int
+  (float)020000000001, // float value, beyond max positive int
+  (float)-020000000001, // float value, beyond max negative int
   0.0,
   -0.1,
   10.0000000000000000005,
@@ -103,7 +103,7 @@ $valid_floats = array(
 $counter = 1;
 /* Loop to check for above float values with var_export() */
 echo "\n*** Output for float values ***\n";
-foreach($valid_bool as $float_value) {
+foreach($valid_floats as $float_value) {
 echo "\nIteration ".$counter."\n";
 var_export( $float_value );
 echo "\n";
@@ -467,39 +467,123 @@ string(5) "false"
 *** Output for float values ***
 
 Iteration 1
-1
-1
-string(1) "1"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
 
 
 Iteration 2
-true
-true
-string(4) "true"
+2147483648.0
+2147483648.0
+string(12) "2147483648.0"
 
 
 Iteration 3
-true
-true
-string(4) "true"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
 
 
 Iteration 4
-0
-0
-string(1) "0"
+34359738369.0
+34359738369.0
+string(13) "34359738369.0"
 
 
 Iteration 5
-false
-false
-string(5) "false"
+2147483649.0
+2147483649.0
+string(12) "2147483649.0"
 
 
 Iteration 6
-false
-false
-string(5) "false"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
+
+
+Iteration 7
+0.0
+0.0
+string(3) "0.0"
+
+
+Iteration 8
+-0.10000000000000001
+-0.10000000000000001
+string(20) "-0.10000000000000001"
+
+
+Iteration 9
+10.0
+10.0
+string(4) "10.0"
+
+
+Iteration 10
+1050000.0
+1050000.0
+string(9) "1050000.0"
+
+
+Iteration 11
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 12
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
+
+
+Iteration 13
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 14
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 15
+100000.0
+100000.0
+string(8) "100000.0"
+
+
+Iteration 16
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
+
+
+Iteration 17
+5000000.0
+5000000.0
+string(9) "5000000.0"
+
+
+Iteration 18
+6.0000000000000006E-20
+6.0000000000000006E-20
+string(22) "6.0000000000000006E-20"
+
+
+Iteration 19
+5.0000000000000001E+42
+5.0000000000000001E+42
+string(22) "5.0000000000000001E+42"
+
+
+Iteration 20
+3.4000000000000001E-33
+3.4000000000000001E-33
+string(22) "3.4000000000000001E-33"
 
 *** Testing var_export() with valid strings ***
 
index cba04b85076476b0b5ad4fa1b576c301b3730a41..5f7b89124c1aa11b3c91fbd077b27a85e4fecfe6 100644 (file)
@@ -22,12 +22,12 @@ $valid_ints = array(
                 "'0x12ab'" => '0x12ab',
                 "'0Xfff'" => '0Xfff',
                 "'0XFA'" => '0XFA',
-                "-0x80000000" => -0x80000000, // max negative integer as hexadecimal
+                "-0x80000000" => -0x7FFFFFFF - 1, // max negative integer as hexadecimal
                 "'0x7fffffff'" => '0x7fffffff',  // max positive integer as hexadecimal
                 "0x7FFFFFFF" => 0x7FFFFFFF,  // max positive integer as hexadecimal
                 "'0123'" => '0123',        // integer as octal
                 "01912" => 01,       // should be quivalent to octal 1
-                "-020000000000" => -020000000000, // max negative integer as octal
+                "-020000000000" => -017777777777 - 1, // max negative integer as octal
                 "017777777777" => 017777777777,  // max positive integer as octal
 );
 
index 58c04481679c75b8dcae8b2d85e81a4979f38eb7..35692ad6274b2c1ed94fbd9a20f52fdf5cee32b2 100644 (file)
@@ -13,12 +13,12 @@ serialize_precision=17
 echo "*** Testing var_export() with valid float values ***\n";
 // different valid  float vlaues 
 $valid_floats = array(
-         "-2147483649" => -2147483649, // float value
-         "2147483648" => 2147483648,  // float value
-         "-0x80000001" => -0x80000001, // float value, beyond max negative int
-         "0x800000001" => 0x800000001, // float value, beyond max positive int
-         "020000000001" => 020000000001, // float value, beyond max positive int
-         "-020000000001" => -020000000001, // float value, beyond max negative int
+         "-2147483649" => (float)-2147483649, // float value
+         "2147483648" => (float)2147483648,  // float value
+         "-0x80000001" => (float)-0x80000001, // float value, beyond max negative int
+         "0x800000001" => (float)0x800000001, // float value, beyond max positive int
+         "020000000001" => (float)020000000001, // float value, beyond max positive int
+         "-020000000001" => (float)-020000000001, // float value, beyond max negative int
          "0.0" => 0.0,
          "-0.1" => -0.1,
          "10.0000000000000000005" => 10.0000000000000000005,
@@ -54,45 +54,45 @@ foreach($valid_floats as $key => $float_value) {
 *** Output for float values ***
 
 -- Iteration: -2147483649 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
 
 
 -- Iteration: 2147483648 --
-2147483648
-2147483648
-string(10) "2147483648"
+2147483648.0
+2147483648.0
+string(12) "2147483648.0"
 
 
 -- Iteration: -0x80000001 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
 
 
 -- Iteration: 0x800000001 --
-34359738369
-34359738369
-string(11) "34359738369"
+34359738369.0
+34359738369.0
+string(13) "34359738369.0"
 
 
 -- Iteration: 020000000001 --
-2147483649
-2147483649
-string(10) "2147483649"
+2147483649.0
+2147483649.0
+string(12) "2147483649.0"
 
 
 -- Iteration: -020000000001 --
--2147483649
--2147483649
-string(11) "-2147483649"
+-2147483649.0
+-2147483649.0
+string(13) "-2147483649.0"
 
 
 -- Iteration: 0.0 --
-0
-0
-string(1) "0"
+0.0
+0.0
+string(3) "0.0"
 
 
 -- Iteration: -0.1 --
@@ -102,21 +102,21 @@ string(20) "-0.10000000000000001"
 
 
 -- Iteration: 10.0000000000000000005 --
-10
-10
-string(2) "10"
+10.0
+10.0
+string(4) "10.0"
 
 
 -- Iteration: 10.5e+5 --
-1050000
-1050000
-string(7) "1050000"
+1050000.0
+1050000.0
+string(9) "1050000.0"
 
 
 -- Iteration: 1e5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
 
 
 -- Iteration: 1e-5 --
@@ -126,21 +126,21 @@ string(21) "1.0000000000000001E-5"
 
 
 -- Iteration: 1e+5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
 
 
 -- Iteration: 1E5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
 
 
 -- Iteration: 1E+5 --
-100000
-100000
-string(6) "100000"
+100000.0
+100000.0
+string(8) "100000.0"
 
 
 -- Iteration: 1E-5 --
@@ -150,9 +150,9 @@ string(21) "1.0000000000000001E-5"
 
 
 -- Iteration: .5e+7 --
-5000000
-5000000
-string(7) "5000000"
+5000000.0
+5000000.0
+string(9) "5000000.0"
 
 
 -- Iteration: .6e-19 --
diff --git a/ext/standard/tests/general_functions/var_export_bug66179.phpt b/ext/standard/tests/general_functions/var_export_bug66179.phpt
new file mode 100644 (file)
index 0000000..1595219
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #66179 (var_export() exports float as integer)
+--FILE--
+<?php
+
+var_export(1.0);
+echo PHP_EOL;
+var_export(123.0);
+echo PHP_EOL;
+var_export(-1.0);
+echo PHP_EOL;
+var_export(-123.0);
+echo PHP_EOL;
+var_export(0.0);
+echo PHP_EOL;
+var_export(-0.0);
+echo PHP_EOL;
+var_export(10000000000000000.0);
+echo PHP_EOL;
+
+?>
+--EXPECTF--
+1.0
+123.0
+-1.0
+-123.0
+0.0
+-0.0
+10000000000000000.0
index 7ae9fcf105b4657c15b7d726677b8b33a5207461..881ac5a2fe8a77928a7478200b00369b93965ac7 100644 (file)
@@ -460,6 +460,13 @@ again:
                case IS_DOUBLE:
                        tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc));
                        smart_str_appendl(buf, tmp_str, tmp_len);
+                       /* Without a decimal point, PHP treats a number literal as an int.
+                        * This check even works for scientific notation, because the
+                        * mantissa always contains a decimal point.
+                        */
+                       if (NULL == strchr(tmp_str, '.')) {
+                               smart_str_appendl(buf, ".0", 2);
+                       }
                        efree(tmp_str);
                        break;
                case IS_STRING:
index d02889101e6f90cdd6b405eab88be46020ff1b0c..ac3d78d06c8e562dae3612bee4b1bead1240e723 100644 (file)
@@ -112,7 +112,7 @@ float(I%s)
 I%s
 I%s
 ------
-0
+0.0
 float(0)
 0
 0
@@ -122,7 +122,7 @@ float(I%s)
 I%s
 I%s
 ------
-0
+0.0
 float(0)
 0
 0