Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)

This commit is contained in:
Dmitry Stogov 2008-07-24 13:46:28 +00:00
parent e29684a2ce
commit 2cca3d0dd2
4 changed files with 41 additions and 0 deletions

View file

@ -2355,6 +2355,19 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
return res;
}
#elif SIZEOF_SIZE_T == 4 && defined(HAVE_ZEND_LONG64)
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
{
zend_ulong64 res = (zend_ulong64)nmemb * (zend_ulong64)size + (zend_ulong64)offset;
if (UNEXPECTED(res > (zend_ulong64)0xFFFFFFFFL)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return (size_t) res;
}
#else
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)