com php-src: Fix some sizeof(zend_long) > sizeof( size_t) issues: Zend/zend_execute.c ext/opcache /Optimizer/zend_inference.c
ext/opcache/zend_persist. c
| From: | Nikita Popov | Date: | Mon, 05 Sep 2016 13:33:02 +0000 |
| Subject: | com php-src: Fix some sizeof(zend_long) > sizeof( size_t) issues: Zend/zend_execute.c ext/opcache /Optimizer/zend_inference.c ext/opcache/zend_persist. c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94325@lists.php.net to get a copy of this message | ||
Commit: daa2b75c76b3364b0caf96ef4d64dd2aedd91aef
Author: Nikita Popov <nikic@php.net> Sun, 4 Sep 2016 23:33:32 +0200
Parents: 750f3d3f65dee4ab58f176b813b4ff78e0d7add1
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=daa2b75c76b3364b0caf96ef4d64dd2aedd91aef
Log:
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.
Changed paths:
M Zend/zend_execute.c
M ext/opcache/Optimizer/zend_inference.c
M ext/opcache/zend_persist.c
Diff:
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index c748a77..545056b 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 1e65a25..62b99e0 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 24a3d21..e022b40 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);
}