From: Nikita Popov Date: Sun, 4 Sep 2016 21:33:32 +0000 (+0200) Subject: Fix some sizeof(zend_long) > sizeof(size_t) issues X-Git-Tag: php-7.2.0alpha1~1332 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=daa2b75c76b3364b0caf96ef4d64dd2aedd91aef;p=php Fix some sizeof(zend_long) > sizeof(size_t) issues Fix a couple of mistakes that are only relevant if sizeof(zend_long) > sizeof(size_t). * Fix cast order in string offset check: Negation should happen after the (zend_long) cast, otherwise sign extension does not occur. * Use Z_UL in zend_inference. * Use aligned size for HT_USED_SIZE in zend_persist: The issue is that on x86-32 uint64_t is considered to be 4-aligned, so the alignment assumption does not hold. --- diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index c748a77711..545056b88c 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1286,7 +1286,7 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zend_long offset; offset = zend_check_string_offset(dim, BP_VAR_W); - if (offset < (zend_long)(-Z_STRLEN_P(str))) { + if (offset < -(zend_long)Z_STRLEN_P(str)) { /* Error on negative offset */ zend_error(E_WARNING, "Illegal string offset: " ZEND_LONG_FMT, offset); if (result) { diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 1e65a2577b..62b99e0472 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -274,7 +274,7 @@ zend_ulong minOR(zend_ulong a, zend_ulong b, zend_ulong c, zend_ulong d) { zend_ulong m, temp; - m = 1L << (sizeof(zend_ulong) * 8 - 1); + m = Z_UL(1) << (sizeof(zend_ulong) * 8 - 1); while (m != 0) { if (~a & c & m) { temp = (a | m) & -m; @@ -298,7 +298,7 @@ zend_ulong maxOR(zend_ulong a, zend_ulong b, zend_ulong c, zend_ulong d) { zend_ulong m, temp; - m = 1L << (sizeof(zend_ulong) * 8 - 1); + m = Z_UL(1) << (sizeof(zend_ulong) * 8 - 1); while (m != 0) { if (b & d & m) { temp = (b - m) | (m - 1); @@ -321,7 +321,7 @@ zend_ulong minAND(zend_ulong a, zend_ulong b, zend_ulong c, zend_ulong d) { zend_ulong m, temp; - m = 1L << (sizeof(zend_ulong) * 8 - 1); + m = Z_UL(1) << (sizeof(zend_ulong) * 8 - 1); while (m != 0) { if (~a & ~c & m) { temp = (a | m) & -m; @@ -344,7 +344,7 @@ zend_ulong maxAND(zend_ulong a, zend_ulong b, zend_ulong c, zend_ulong d) { zend_ulong m, temp; - m = 1L << (sizeof(zend_ulong) * 8 - 1); + m = Z_UL(1) << (sizeof(zend_ulong) * 8 - 1); while (m != 0) { if (b & ~d & m) { temp = (b | ~m) | (m - 1); diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 24a3d21ca2..e022b40950 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -133,7 +133,7 @@ static void zend_hash_persist(HashTable *ht, zend_persist_func_t pPersistElement void *old_data = HT_GET_DATA_ADDR(ht); ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ - ZCG(mem) = (void*)((char*)data + HT_USED_SIZE(ht)); + ZCG(mem) = (void*)((char*)data + ZEND_ALIGNED_SIZE(HT_USED_SIZE(ht))); memcpy(data, old_data, HT_USED_SIZE(ht)); efree(old_data); HT_SET_DATA_ADDR(ht, data); @@ -214,7 +214,7 @@ static void zend_hash_persist_immutable(HashTable *ht) void *data = ZCG(mem); ZEND_ASSERT(((zend_uintptr_t)ZCG(mem) & 0x7) == 0); /* should be 8 byte aligned */ - ZCG(mem) = (void*)((char*)data + HT_USED_SIZE(ht)); + ZCG(mem) = (void*)((char*)data + ZEND_ALIGNED_SIZE(HT_USED_SIZE(ht))); memcpy(data, HT_GET_DATA_ADDR(ht), HT_USED_SIZE(ht)); HT_SET_DATA_ADDR(ht, data); }