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.
This commit is contained in:
Nikita Popov 2016-09-04 23:33:32 +02:00
parent 750f3d3f65
commit daa2b75c76
3 changed files with 7 additions and 7 deletions

View 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) {

View 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);

View 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);
}