Skip to content

Commit

Permalink
Check non-zero in is_power_of_two()
Browse files Browse the repository at this point in the history
And assert non-zero in floor_log2().

Fixes DASM_S_RANGE_I in ext/simplexml/tests/021.phpt.
  • Loading branch information
nikic committed Jul 30, 2020
1 parent 849c741 commit 3690a80
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ static uint32_t ones32(uint32_t x)

static uint32_t floor_log2(uint32_t x)
{
ZEND_ASSERT(x != 0);
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
Expand All @@ -1623,7 +1624,7 @@ static uint32_t floor_log2(uint32_t x)

static zend_bool is_power_of_two(uint32_t x)
{
return !(x & (x - 1));
return !(x & (x - 1)) && x != 0;
}

static zend_bool has_concrete_type(uint32_t value_type)
Expand Down

0 comments on commit 3690a80

Please sign in to comment.