1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Implement zend_safe_address() for MSVC 64bit (GH-17679)

The 32bit implementation seems to be okay, but we rather should avoid
falling back to the double (pun intended) calculation for non `__GNUC__`
systems.  We use the intsafe.h intrinsics instead for MSVC and
compatible compilers.
This commit is contained in:
Christoph M. Becker
2025-02-14 17:37:27 +01:00
committed by GitHub
parent e9ffe02fa1
commit 7c8bd08f6d

View File

@@ -290,6 +290,19 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
return (size_t) res;
}
#elif defined(_MSC_VER)
static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, bool *overflow)
{
size_t res;
if (UNEXPECTED(FAILED(ULongLongMult(nmemb, size, &res)) || FAILED(ULongLongAdd(res, offset, &res)))) {
*overflow = 1;
return 0;
}
*overflow = 0;
return res;
}
#else
static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, bool *overflow)