]> granicus.if.org Git - php/commitdiff
Fix some sizeof(zend_long) > sizeof(size_t) issues
authorNikita Popov <nikic@php.net>
Sun, 4 Sep 2016 21:33:32 +0000 (23:33 +0200)
committerNikita Popov <nikic@php.net>
Mon, 5 Sep 2016 13:33:02 +0000 (15:33 +0200)
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.

Zend/zend_execute.c
ext/opcache/Optimizer/zend_inference.c
ext/opcache/zend_persist.c

index c748a777111cb36adab4582db256db21053ea85e..545056b88c9b9e03519508061484665b80f95387 100644 (file)
@@ -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) {
index 1e65a2577b7c25b047b8a69070cd3fc0ebf57ac7..62b99e0472b5f98d0854ca08e8da4e0112ec551f 100644 (file)
@@ -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);
index 24a3d21ca279952f20f524d5d02d862d67b7573e..e022b40950a94e2d1a2b6b67550a3c55982c6f6f 100644 (file)
@@ -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);
        }