Skip to content

Commit 3daa8e3

Browse files
committed
Handle negative zero
1 parent d55c30e commit 3daa8e3

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,16 @@ static zend_bool spl_fixedarray_shallow_identical(zval *v1, zval *v2)
212212
case IS_LONG:
213213
return Z_LVAL_P(v1) == Z_LVAL_P(v2);
214214
case IS_DOUBLE: {
215+
uint64_t raw1 = *(uint64_t *)(&v1->value);
216+
uint64_t raw2 = *(uint64_t *)(&v2->value);
217+
if (EXPECTED(raw1 == raw2)) {
218+
/* Same bit representation, e.g. for ordinary numbers or positive/negative zero. */
219+
return true;
220+
}
215221
double d1 = Z_DVAL_P(v1);
216222
double d2 = Z_DVAL_P(v2);
217223
/* Also check for NAN */
218-
return d1 == d2 || (d1 != d1 && d2 != d2);
224+
return (d1 != d1 && d2 != d2);
219225
}
220226
case IS_STRING:
221227
return Z_STR_P(v1) == Z_STR_P(v2); /* Same pointer */

ext/spl/tests/fixedarray_023.phpt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@ SPL: FixedArray: Infinite loop in var_export bugfix
33
--FILE--
44
<?php
55
call_user_func(function () {
6-
$x = new SplFixedArray(3);
6+
$x = new SplFixedArray(4);
77
$x[0] = NAN; // Test NAN just in case this check is incorrectly refactored to use zend_is_identical
8-
$x[1] = $x;
8+
$x[1] = 0.0;
99
$x[2] = $x;
10+
$x[3] = $x;
1011
var_export($x);
1112
echo "\n";
13+
$x[1] = -0.0;
1214
debug_zval_dump($x);
1315
});
1416
?>
1517
--EXPECTF--
16-
Warning: var_export does not handle circular references in %s on line 7
18+
Warning: var_export does not handle circular references in %s on line 8
1719

18-
Warning: var_export does not handle circular references in %s on line 7
20+
Warning: var_export does not handle circular references in %s on line 8
1921
SplFixedArray::__set_state(array(
2022
0 => NAN,
21-
1 => NULL,
23+
1 => 0.0,
2224
2 => NULL,
25+
3 => NULL,
2326
))
24-
object(SplFixedArray)#2 (3) refcount(6){
27+
object(SplFixedArray)#2 (4) refcount(6){
2528
[0]=>
2629
float(NAN)
2730
[1]=>
28-
*RECURSION*
31+
float(-0)
2932
[2]=>
3033
*RECURSION*
31-
}
34+
[3]=>
35+
*RECURSION*
36+
}

0 commit comments

Comments
 (0)