Permalink
Browse files

Fixed bug #62097

This fixes the fix for bug #54547 in 32-bit machines by accepting
float comparisons in 32-bit machines as long as the integer is
not larger than the mantissa.
  • Loading branch information...
1 parent bdf0c9c commit 03f369dedd743a5f545e84fd78dcce2dc9e1790a @cataphract committed May 22, 2012
Showing with 23 additions and 0 deletions.
  1. +17 −0 Zend/tests/bug62097.phpt
  2. +6 −0 Zend/zend_operators.c
View
@@ -0,0 +1,17 @@
+--TEST--
+Bug #62097: fix for bug #54547 is wrong for 32-bit machines
+--SKIPIF--
+<php
+if (PHP_INT_MAX !== 2147483647)
+ die('skip for system with 32-bit wide longs only');
+--FILE--
+<?php
+var_dump("02147483647" == "2147483647",
+ "02147483648" == "2147483648",
+ "09007199254740991" == "9007199254740991",
+ "09007199254740992" == "9007199254740992");
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(false)
View
@@ -2041,7 +2041,13 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
if ((ret1=is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
(ret2=is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
+#if ULONG_MAX == 0xFFFFFFFF
+ if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
+ ((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
+ || (oflow1 == -1 && dval1 < -9007199254740991.))) {
+#else
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0.) {
+#endif
/* both values are integers overflown to the same side, and the
* double comparison may have resulted in crucial accuracy lost */
goto string_cmp;

0 comments on commit 03f369d

Please sign in to comment.