Skip to content

Commit 3690a80

Browse files
committed
Check non-zero in is_power_of_two()
And assert non-zero in floor_log2(). Fixes DASM_S_RANGE_I in ext/simplexml/tests/021.phpt.
1 parent 849c741 commit 3690a80

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ static uint32_t ones32(uint32_t x)
16131613

16141614
static uint32_t floor_log2(uint32_t x)
16151615
{
1616+
ZEND_ASSERT(x != 0);
16161617
x |= (x >> 1);
16171618
x |= (x >> 2);
16181619
x |= (x >> 4);
@@ -1623,7 +1624,7 @@ static uint32_t floor_log2(uint32_t x)
16231624

16241625
static zend_bool is_power_of_two(uint32_t x)
16251626
{
1626-
return !(x & (x - 1));
1627+
return !(x & (x - 1)) && x != 0;
16271628
}
16281629

16291630
static zend_bool has_concrete_type(uint32_t value_type)

0 commit comments

Comments
 (0)