Skip to content

Commit 78ff9eb

Browse files
cataphractsmalyshev
authored andcommitted
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.
1 parent 9ab21b1 commit 78ff9eb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Zend/tests/bug62097.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #62097: fix for bug #54547 is wrong for 32-bit machines
3+
--SKIPIF--
4+
<php
5+
if (PHP_INT_MAX !== 2147483647)
6+
die('skip for system with 32-bit wide longs only');
7+
--FILE--
8+
<?php
9+
var_dump("02147483647" == "2147483647",
10+
"02147483648" == "2147483648",
11+
"09007199254740991" == "9007199254740991",
12+
"09007199254740992" == "9007199254740992");
13+
--EXPECT--
14+
bool(true)
15+
bool(true)
16+
bool(true)
17+
bool(false)

Zend/zend_operators.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,13 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) /* {{{ */
20412041

20422042
if ((ret1=is_numeric_string_ex(Z_STRVAL_P(s1), Z_STRLEN_P(s1), &lval1, &dval1, 0, &oflow1)) &&
20432043
(ret2=is_numeric_string_ex(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0, &oflow2))) {
2044+
#if ULONG_MAX == 0xFFFFFFFF
2045+
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0. &&
2046+
((oflow1 == 1 && dval1 > 9007199254740991. /*0x1FFFFFFFFFFFFF*/)
2047+
|| (oflow1 == -1 && dval1 < -9007199254740991.))) {
2048+
#else
20442049
if (oflow1 != 0 && oflow1 == oflow2 && dval1 - dval2 == 0.) {
2050+
#endif
20452051
/* both values are integers overflown to the same side, and the
20462052
* double comparison may have resulted in crucial accuracy lost */
20472053
goto string_cmp;

0 commit comments

Comments
 (0)