Skip to content

Commit d91b166

Browse files
committed
Avoid shift UB for large arrays
Don't shift into the sign bit.
1 parent 7db3a51 commit d91b166

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Zend/zend_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ static zend_always_inline uint32_t zend_hash_check_size(uint32_t nSize)
102102

103103
#if defined(ZEND_WIN32)
104104
if (BitScanReverse(&index, nSize - 1)) {
105-
return 0x2 << ((31 - index) ^ 0x1f);
105+
return 0x2u << ((31 - index) ^ 0x1f);
106106
} else {
107107
/* nSize is ensured to be in the valid range, fall back to it
108108
rather than using an undefined bis scan result. */
109109
return nSize;
110110
}
111111
#elif (defined(__GNUC__) || __has_builtin(__builtin_clz)) && defined(PHP_HAVE_BUILTIN_CLZ)
112-
return 0x2 << (__builtin_clz(nSize - 1) ^ 0x1f);
112+
return 0x2u << (__builtin_clz(nSize - 1) ^ 0x1f);
113113
#else
114114
nSize -= 1;
115115
nSize |= (nSize >> 1);

0 commit comments

Comments
 (0)