]> granicus.if.org Git - php/commitdiff
Check non-zero in is_power_of_two()
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 30 Jul 2020 08:17:37 +0000 (10:17 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 30 Jul 2020 08:17:37 +0000 (10:17 +0200)
And assert non-zero in floor_log2().

Fixes DASM_S_RANGE_I in ext/simplexml/tests/021.phpt.

ext/opcache/jit/zend_jit_x86.dasc

index 5c827f4b99aa75892696101962f562b7a4f18bfa..107e2c5de82ee26f9a1f6ebb37c37d9aeaf0405d 100644 (file)
@@ -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);
@@ -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)