diff options
author | Andrea Faulds <ajf@ajf.me> | 2014-09-17 20:15:32 +0100 |
---|---|---|
committer | Andrea Faulds <ajf@ajf.me> | 2014-09-17 20:15:32 +0100 |
commit | 7f51d73bb2aef3fb8b50b6a7e76ebb11f86813fa (patch) | |
tree | abb31b78ec4ddef3c95f223bc58b1c632e526109 | |
parent | db72160e5ac2b267b9ffa23ad84e62e609382a44 (diff) | |
parent | e3b3e6812772f5739641d85a89855c085c32e17f (diff) | |
download | php-git-7f51d73bb2aef3fb8b50b6a7e76ebb11f86813fa.tar.gz |
Merge branch 'master' into integer_semantics
-rw-r--r-- | Zend/tests/034.phpt | 4 | ||||
-rw-r--r-- | Zend/zend_compile.c | 8 | ||||
-rw-r--r-- | Zend/zend_execute.c | 155 | ||||
-rw-r--r-- | Zend/zend_hash.c | 138 | ||||
-rw-r--r-- | Zend/zend_hash.h | 8 | ||||
-rw-r--r-- | Zend/zend_ts_hash.c | 4 | ||||
-rw-r--r-- | Zend/zend_ts_hash.h | 6 | ||||
-rw-r--r-- | Zend/zend_vm_def.h | 47 | ||||
-rw-r--r-- | Zend/zend_vm_execute.h | 85 | ||||
-rw-r--r-- | ext/iconv/iconv.c | 6 | ||||
-rw-r--r-- | ext/json/utf8_decode.h | 2 | ||||
-rw-r--r-- | ext/mbstring/mbstring.c | 2 | ||||
-rw-r--r-- | ext/mbstring/php_mbregex.c | 4 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd.c | 2 | ||||
-rw-r--r-- | ext/opcache/Optimizer/compact_literals.c | 4 | ||||
-rw-r--r-- | ext/pdo/pdo_sql_parser.c | 2 | ||||
-rw-r--r-- | ext/session/session.c | 3 | ||||
-rw-r--r-- | ext/spl/spl_directory.c | 7 | ||||
-rw-r--r-- | ext/spl/spl_dllist.c | 2 | ||||
-rw-r--r-- | ext/standard/array.c | 11 | ||||
-rw-r--r-- | ext/standard/basic_functions.c | 3 | ||||
-rw-r--r-- | ext/standard/info.c | 2 | ||||
-rw-r--r-- | ext/standard/string.c | 55 | ||||
-rw-r--r-- | ext/zip/lib/zip_set_name.c | 2 | ||||
-rw-r--r-- | ext/zlib/zlib_filter.c | 2 |
25 files changed, 324 insertions, 240 deletions
diff --git a/Zend/tests/034.phpt b/Zend/tests/034.phpt index 6e46f2645e..0bcfa23f19 100644 --- a/Zend/tests/034.phpt +++ b/Zend/tests/034.phpt @@ -22,5 +22,5 @@ switch (1) { } ?> ---EXPECT-- -3 +--EXPECTF-- +Fatal error: Switch statements may only contain one default clause in %s on line 13 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5beacab0b6..df44138d4f 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4586,7 +4586,8 @@ void zend_compile_global_var(zend_ast *ast TSRMLS_DC) /* {{{ */ } if (zend_try_compile_cv(&result, var_ast TSRMLS_CC) == SUCCESS) { - zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node TSRMLS_CC); + zend_op *opline = zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node TSRMLS_CC); + zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC); } else { zend_emit_op(&result, ZEND_FETCH_W, &name_node, NULL TSRMLS_CC); @@ -5089,6 +5090,11 @@ void zend_compile_switch(zend_ast *ast TSRMLS_DC) /* {{{ */ znode cond_node; if (!cond_ast) { + if (has_default_case) { + CG(zend_lineno) = case_ast->lineno; + zend_error_noreturn(E_COMPILE_ERROR, + "Switch statements may only contain one default clause"); + } has_default_case = 1; continue; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 0c8e7379d7..19ecb0bc04 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1457,49 +1457,59 @@ void zend_free_compiled_variables(zend_execute_data *execute_data TSRMLS_DC) /* static zend_always_inline void i_init_func_execute_data(zend_execute_data *execute_data, zend_op_array *op_array, zval *return_value, vm_frame_kind frame_kind TSRMLS_DC) /* {{{ */ { - uint32_t first_extra_arg; + uint32_t first_extra_arg, num_args; ZEND_ASSERT(EX(func) == (zend_function*)op_array); ZEND_ASSERT(EX(object) == Z_OBJ(EG(This))); - EX(return_value) = return_value; - EX(frame_kind) = frame_kind; - ZVAL_UNDEF(&EX(old_error_reporting)); - EX(delayed_exception) = NULL; - EX(call) = NULL; - EX(opline) = op_array->opcodes; - if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { - /* Skip useless ZEND_RECV opcodes */ - EX(opline) += MIN(EX(num_args), op_array->required_num_args); - } + EX(call) = NULL; + EX(frame_kind) = frame_kind; + EX(return_value) = return_value; EX(scope) = EG(scope); + EX(delayed_exception) = NULL; + ZVAL_UNDEF(&EX(old_error_reporting)); + /* Handle arguments */ first_extra_arg = op_array->num_args; - if (UNEXPECTED((op_array->fn_flags & ZEND_ACC_VARIADIC) != 0)) { first_extra_arg--; } - if (UNEXPECTED(EX(num_args) > first_extra_arg)) { - /* move extra args into separate array after all CV and TMP vars */ - zval *extra_args = EX_VAR_NUM(op_array->last_var + op_array->T); - - memmove(extra_args, EX_VAR_NUM(first_extra_arg), sizeof(zval) * (EX(num_args) - first_extra_arg)); - } + num_args = EX(num_args); + if (UNEXPECTED(num_args > first_extra_arg)) { + zval *end, *src, *dst; - do { - /* Initialize CV variables (skip arguments) */ - int num_args = MIN(op_array->num_args, EX(num_args)); - - if (EXPECTED(num_args < op_array->last_var)) { - zval *var = EX_VAR_NUM(num_args); - zval *end = EX_VAR_NUM(op_array->last_var); + if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { + /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ + EX(opline) += first_extra_arg; + } + /* move extra args into separate array after all CV and TMP vars */ + end = EX_VAR_NUM(first_extra_arg - 1); + src = end + (num_args - first_extra_arg); + dst = src + (op_array->last_var + op_array->T - first_extra_arg); + if (EXPECTED(src != dst)) { do { - ZVAL_UNDEF(var); - var++; - } while (var != end); + ZVAL_COPY_VALUE(dst, src); + ZVAL_UNDEF(src); + src--; + dst--; + } while (src != end); } - } while (0); + } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { + /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ + EX(opline) += num_args; + } + + /* Initialize CV variables (skip arguments) */ + if (EXPECTED(num_args < op_array->last_var)) { + zval *var = EX_VAR_NUM(num_args); + zval *end = EX_VAR_NUM(op_array->last_var); + + do { + ZVAL_UNDEF(var); + var++; + } while (var != end); + } if (op_array->this_var != -1 && EX(object)) { ZVAL_OBJ(EX_VAR(op_array->this_var), EX(object)); @@ -1507,11 +1517,7 @@ static zend_always_inline void i_init_func_execute_data(zend_execute_data *execu } if (!op_array->run_time_cache && op_array->last_cache_slot) { - if (op_array->function_name) { - op_array->run_time_cache = zend_arena_calloc(&CG(arena), op_array->last_cache_slot, sizeof(void*)); - } else { - op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*)); - } + op_array->run_time_cache = zend_arena_calloc(&CG(arena), op_array->last_cache_slot, sizeof(void*)); } EX(run_time_cache) = op_array->run_time_cache; @@ -1524,23 +1530,18 @@ static zend_always_inline void i_init_code_execute_data(zend_execute_data *execu ZEND_ASSERT(EX(func) == (zend_function*)op_array); ZEND_ASSERT(EX(object) == Z_OBJ(EG(This))); - EX(return_value) = return_value; - EX(frame_kind) = frame_kind; - ZVAL_UNDEF(&EX(old_error_reporting)); - EX(delayed_exception) = NULL; - EX(call) = NULL; - EX(opline) = op_array->opcodes; + EX(call) = NULL; + EX(frame_kind) = frame_kind; + EX(return_value) = return_value; EX(scope) = EG(scope); + EX(delayed_exception) = NULL; + ZVAL_UNDEF(&EX(old_error_reporting)); zend_attach_symbol_table(execute_data); if (!op_array->run_time_cache && op_array->last_cache_slot) { - if (op_array->function_name) { - op_array->run_time_cache = zend_arena_calloc(&CG(arena), op_array->last_cache_slot, sizeof(void*)); - } else { - op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*)); - } + op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*)); } EX(run_time_cache) = op_array->run_time_cache; @@ -1553,44 +1554,60 @@ static zend_always_inline void i_init_execute_data(zend_execute_data *execute_da ZEND_ASSERT(EX(func) == (zend_function*)op_array); ZEND_ASSERT(EX(object) == Z_OBJ(EG(This))); - EX(return_value) = return_value; - EX(frame_kind) = frame_kind; - ZVAL_UNDEF(&EX(old_error_reporting)); - EX(delayed_exception) = NULL; - EX(call) = NULL; - EX(opline) = op_array->opcodes; + EX(call) = NULL; + EX(frame_kind) = frame_kind; + EX(return_value) = return_value; EX(scope) = EG(scope); + EX(delayed_exception) = NULL; + ZVAL_UNDEF(&EX(old_error_reporting)); if (UNEXPECTED(EX(symbol_table) != NULL)) { zend_attach_symbol_table(execute_data); } else { - uint32_t first_extra_arg = op_array->num_args; + uint32_t first_extra_arg, num_args; + /* Handle arguments */ + first_extra_arg = op_array->num_args; if (UNEXPECTED((op_array->fn_flags & ZEND_ACC_VARIADIC) != 0)) { first_extra_arg--; } - if (UNEXPECTED(EX(num_args) > first_extra_arg)) { - /* move extra args into separate array after all CV and TMP vars */ - zval *extra_args = EX_VAR_NUM(op_array->last_var + op_array->T); - - memmove(extra_args, EX_VAR_NUM(first_extra_arg), sizeof(zval) * (EX(num_args) - first_extra_arg)); - } + num_args = EX(num_args); + if (UNEXPECTED(num_args > first_extra_arg)) { + zval *end, *src, *dst; - do { - /* Initialize CV variables (skip arguments) */ - int num_args = MIN(op_array->num_args, EX(num_args)); - - if (EXPECTED(num_args < op_array->last_var)) { - zval *var = EX_VAR_NUM(num_args); - zval *end = EX_VAR_NUM(op_array->last_var); + if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { + /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ + EX(opline) += first_extra_arg; + } + /* move extra args into separate array after all CV and TMP vars */ + end = EX_VAR_NUM(first_extra_arg - 1); + src = end + (num_args - first_extra_arg); + dst = src + (op_array->last_var + op_array->T - first_extra_arg); + if (EXPECTED(src != dst)) { do { - ZVAL_UNDEF(var); - var++; - } while (var != end); + ZVAL_COPY_VALUE(dst, src); + ZVAL_UNDEF(src); + src--; + dst--; + } while (src != end); } - } while (0); + } else if (EXPECTED((op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS) == 0)) { + /* Skip useless ZEND_RECV and ZEND_RECV_INIT opcodes */ + EX(opline) += num_args; + } + + /* Initialize CV variables (skip arguments) */ + if (EXPECTED(num_args < op_array->last_var)) { + zval *var = EX_VAR_NUM(num_args); + zval *end = EX_VAR_NUM(op_array->last_var); + + do { + ZVAL_UNDEF(var); + var++; + } while (var != end); + } if (op_array->this_var != -1 && EX(object)) { ZVAL_OBJ(EX_VAR(op_array->this_var), EX(object)); diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index e651cd85e5..e603069e4a 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -402,7 +402,7 @@ ZEND_API zval *zend_hash_str_add_empty_element(HashTable *ht, const char *str, s return zend_hash_str_add(ht, str, len, &dummy); } -static zend_always_inline zval *_zend_hash_index_update_or_next_insert_i(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) +static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) { uint32_t nIndex; uint32_t idx; @@ -412,75 +412,70 @@ static zend_always_inline zval *_zend_hash_index_update_or_next_insert_i(HashTab #endif IS_CONSISTENT(ht); - - if (flag & HASH_NEXT_INSERT) { - h = ht->nNextFreeElement; - } - CHECK_INIT(ht, h >= 0 && h < ht->nTableSize); + CHECK_INIT(ht, h < ht->nTableSize); if (ht->u.flags & HASH_FLAG_PACKED) { - if (EXPECTED(h >= 0)) { - if (h < ht->nNumUsed) { - p = ht->arData + h; - if (Z_TYPE(p->val) != IS_UNDEF) { - if (flag & (HASH_NEXT_INSERT | HASH_ADD)) { - return NULL; - } - if (ht->pDestructor) { - ht->pDestructor(&p->val); - } - ZVAL_COPY_VALUE(&p->val, pData); - if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { - ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; - } - return &p->val; - } else { /* we have to keep the order :( */ - goto convert_to_hash; + if (h < ht->nNumUsed) { + p = ht->arData + h; + if (Z_TYPE(p->val) != IS_UNDEF) { + if (flag & HASH_ADD) { + return NULL; } - } else if (EXPECTED(h < ht->nTableSize)) { - p = ht->arData + h; - } else if (h < ht->nTableSize * 2 && - ht->nTableSize - ht->nNumOfElements < ht->nTableSize / 2) { - zend_hash_packed_grow(ht); - p = ht->arData + h; - } else { - goto convert_to_hash; - } - HANDLE_BLOCK_INTERRUPTIONS(); - /* incremental initialization of empty Buckets */ - if (h >= ht->nNumUsed) { - Bucket *q = ht->arData + ht->nNumUsed; - while (q != p) { - ZVAL_UNDEF(&q->val); - q++; + if (ht->pDestructor) { + ht->pDestructor(&p->val); } - ht->nNumUsed = h + 1; - } - ht->nNumOfElements++; - if (ht->nInternalPointer == INVALID_IDX) { - ht->nInternalPointer = h; + ZVAL_COPY_VALUE(&p->val, pData); + if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { + ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; + } + return &p->val; + } else { /* we have to keep the order :( */ + goto convert_to_hash; } - if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { - ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; + } else if (EXPECTED(h < ht->nTableSize)) { + p = ht->arData + h; + } else if (h < ht->nTableSize * 2 && + ht->nTableSize - ht->nNumOfElements < ht->nTableSize / 2) { + zend_hash_packed_grow(ht); + p = ht->arData + h; + } else { + goto convert_to_hash; + } + + HANDLE_BLOCK_INTERRUPTIONS(); + /* incremental initialization of empty Buckets */ + if (h >= ht->nNumUsed) { + Bucket *q = ht->arData + ht->nNumUsed; + while (q != p) { + ZVAL_UNDEF(&q->val); + q++; } - p->h = h; - p->key = NULL; - ZVAL_COPY_VALUE(&p->val, pData); - Z_NEXT(p->val) = INVALID_IDX; + ht->nNumUsed = h + 1; + } + ht->nNumOfElements++; + if (ht->nInternalPointer == INVALID_IDX) { + ht->nInternalPointer = h; + } + if ((zend_long)h >= (zend_long)ht->nNextFreeElement) { + ht->nNextFreeElement = h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; + } + p->h = h; + p->key = NULL; + ZVAL_COPY_VALUE(&p->val, pData); + Z_NEXT(p->val) = INVALID_IDX; - HANDLE_UNBLOCK_INTERRUPTIONS(); + HANDLE_UNBLOCK_INTERRUPTIONS(); + + return &p->val; - return &p->val; - } else { convert_to_hash: - zend_hash_packed_to_hash(ht); - } + zend_hash_packed_to_hash(ht); } if ((flag & HASH_ADD_NEW) == 0) { p = zend_hash_index_find_bucket(ht, h); if (p) { - if (flag & (HASH_NEXT_INSERT | HASH_ADD)) { + if (flag & HASH_ADD) { return NULL; } ZEND_ASSERT(&p->val != pData); @@ -520,34 +515,34 @@ convert_to_hash: return &p->val; } -ZEND_API zval *_zend_hash_index_update_or_next_insert(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) +ZEND_API zval *_zend_hash_index_add_or_update(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, h, pData, flag ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, h, pData, flag ZEND_FILE_LINE_RELAY_CC); } ZEND_API zval *_zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, h, pData, HASH_ADD ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, h, pData, HASH_ADD ZEND_FILE_LINE_RELAY_CC); } ZEND_API zval *_zend_hash_index_add_new(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, h, pData, HASH_ADD | HASH_ADD_NEW ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, h, pData, HASH_ADD | HASH_ADD_NEW ZEND_FILE_LINE_RELAY_CC); } ZEND_API zval *_zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, h, pData, HASH_UPDATE ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, h, pData, HASH_UPDATE ZEND_FILE_LINE_RELAY_CC); } ZEND_API zval *_zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, ht->nNextFreeElement, pData, HASH_NEXT_INSERT ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, ht->nNextFreeElement, pData, HASH_ADD ZEND_FILE_LINE_RELAY_CC); } ZEND_API zval *_zend_hash_next_index_insert_new(HashTable *ht, zval *pData ZEND_FILE_LINE_DC) { - return _zend_hash_index_update_or_next_insert_i(ht, ht->nNextFreeElement, pData, HASH_NEXT_INSERT | HASH_ADD_NEW ZEND_FILE_LINE_RELAY_CC); + return _zend_hash_index_add_or_update_i(ht, ht->nNextFreeElement, pData, HASH_ADD | HASH_ADD_NEW ZEND_FILE_LINE_RELAY_CC); } static void zend_hash_do_resize(HashTable *ht) @@ -648,19 +643,18 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, static zend_always_inline void _zend_hash_del_el(HashTable *ht, uint32_t idx, Bucket *p) { - uint32_t nIndex; Bucket *prev = NULL; if (!(ht->u.flags & HASH_FLAG_PACKED)) { - nIndex = p->h & ht->nTableMask; - idx = ht->arHash[nIndex]; - if (p != ht->arData + idx) { - prev = ht->arData + idx; - while (ht->arData + Z_NEXT(prev->val) != p) { - idx = Z_NEXT(prev->val); - prev = ht->arData + idx; + uint32_t nIndex = p->h & ht->nTableMask; + uint32_t i = ht->arHash[nIndex]; + + if (i != idx) { + prev = ht->arData + i; + while (Z_NEXT(prev->val) != idx) { + i = Z_NEXT(prev->val); + prev = ht->arData + i; } - idx = Z_NEXT(prev->val); } } diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 6752ccb074..a6bb67a1f2 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -27,13 +27,11 @@ #define HASH_KEY_IS_STRING 1 #define HASH_KEY_IS_LONG 2 #define HASH_KEY_NON_EXISTENT 3 -#define HASH_KEY_NON_EXISTANT HASH_KEY_NON_EXISTENT /* Keeping old define (with typo) for backward compatibility */ #define HASH_UPDATE (1<<0) #define HASH_ADD (1<<1) -#define HASH_NEXT_INSERT (1<<2) -#define HASH_UPDATE_INDIRECT (1<<3) -#define HASH_ADD_NEW (1<<4) +#define HASH_UPDATE_INDIRECT (1<<2) +#define HASH_ADD_NEW (1<<3) #define INVALID_IDX ((uint32_t) -1) @@ -97,7 +95,7 @@ ZEND_API zval *_zend_hash_str_add_new(HashTable *ht, const char *key, size_t len #define zend_hash_str_add_new(ht, key, len, pData) \ _zend_hash_str_add_new(ht, key, len, pData ZEND_FILE_LINE_CC) -ZEND_API zval *_zend_hash_index_update_or_next_insert(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC); +ZEND_API zval *_zend_hash_index_add_or_update(HashTable *ht, zend_ulong h, zval *pData, uint32_t flag ZEND_FILE_LINE_DC); ZEND_API zval *_zend_hash_index_add(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC); ZEND_API zval *_zend_hash_index_add_new(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC); ZEND_API zval *_zend_hash_index_update(HashTable *ht, zend_ulong h, zval *pData ZEND_FILE_LINE_DC); diff --git a/Zend/zend_ts_hash.c b/Zend/zend_ts_hash.c index b289ae17c9..43f02b48f8 100644 --- a/Zend/zend_ts_hash.c +++ b/Zend/zend_ts_hash.c @@ -110,12 +110,12 @@ ZEND_API zval *_zend_ts_hash_add_or_update(TsHashTable *ht, zend_string *key, zv return retval; } -ZEND_API zval *_zend_ts_hash_index_update_or_next_insert(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC) +ZEND_API zval *_zend_ts_hash_index_add_or_update(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC) { zval *retval; begin_write(ht); - retval = _zend_hash_index_update_or_next_insert(TS_HASH(ht), h, pData, flag ZEND_FILE_LINE_RELAY_CC); + retval = _zend_hash_index_add_or_update(TS_HASH(ht), h, pData, flag ZEND_FILE_LINE_RELAY_CC); end_write(ht); return retval; diff --git a/Zend/zend_ts_hash.h b/Zend/zend_ts_hash.h index 0adedff437..3d05dd572d 100644 --- a/Zend/zend_ts_hash.h +++ b/Zend/zend_ts_hash.h @@ -55,11 +55,11 @@ ZEND_API zval *_zend_ts_hash_add_or_update(TsHashTable *ht, zend_string *key, zv #define zend_ts_hash_add(ht, key, pData) \ _zend_ts_hash_add_or_update(ht, key, pData, HASH_ADD ZEND_FILE_LINE_CC) -ZEND_API zval *_zend_ts_hash_index_update_or_next_insert(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC); +ZEND_API zval *_zend_ts_hash_index_add_or_update(TsHashTable *ht, zend_ulong h, zval *pData, int flag ZEND_FILE_LINE_DC); #define zend_ts_hash_index_update(ht, h, pData) \ - _zend_ts_hash_index_update_or_next_insert(ht, h, pData, HASH_UPDATE ZEND_FILE_LINE_CC) + _zend_ts_hash_index_add_or_update(ht, h, pData, HASH_UPDATE ZEND_FILE_LINE_CC) #define zend_ts_hash_next_index_insert(ht, pData) \ - _zend_ts_hash_index_update_or_next_insert(ht, 0, pData, HASH_NEXT_INSERT ZEND_FILE_LINE_CC) + _zend_ts_hash_index_add_or_update(ht, ht->nNextFreeElement, pData, HASH_ADD ZEND_FILE_LINE_CC) ZEND_API zval* zend_ts_hash_add_empty_element(TsHashTable *ht, zend_string *key); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a3ae246579..ac015aea52 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5067,7 +5067,7 @@ ZEND_VM_C_LABEL(num_index_prop): } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -5891,19 +5891,46 @@ ZEND_VM_HANDLER(168, ZEND_BIND_GLOBAL, CV, CONST) zval *varname; zval *value; zval *variable_ptr; - zend_string *name; + Bucket *p; + uint32_t idx; SAVE_OPLINE(); varname = GET_OP2_ZVAL_PTR(BP_VAR_R); - name = Z_STR_P(varname); - value = zend_hash_find(&EG(symbol_table).ht, name); - if (value == NULL) { - value = zend_hash_add_new(&EG(symbol_table).ht, name, &EG(uninitialized_zval)); + idx = (uint32_t)(uintptr_t)CACHED_PTR(Z_CACHE_SLOT_P(varname)); + /* index 0 can't be cached (NULL is a mark of uninitialized cache slot) */ + p = EG(symbol_table).ht.arData + idx; + if (EXPECTED(idx > 0) && + EXPECTED(idx < EG(symbol_table).ht.nNumUsed) && + EXPECTED(Z_TYPE(p->val) != IS_UNDEF) && + (EXPECTED(p->key == Z_STR_P(varname)) || + (EXPECTED(p->h == Z_STR_P(varname)->h) && + EXPECTED(p->key != NULL) && + EXPECTED(p->key->len == Z_STRLEN_P(varname)) && + EXPECTED(memcmp(p->key->val, Z_STRVAL_P(varname), Z_STRLEN_P(varname)) == 0)))) { + value = &EG(symbol_table).ht.arData[idx].val; /* GLOBAL variable may be an INDIRECT pointer to CV */ - } else if (Z_TYPE_P(value) == IS_INDIRECT) { - value = Z_INDIRECT_P(value); - if (Z_TYPE_P(value) == IS_UNDEF) { - ZVAL_NULL(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + value = Z_INDIRECT_P(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + ZVAL_NULL(value); + } + } + } else { + value = zend_hash_find(&EG(symbol_table).ht, Z_STR_P(varname)); + if (UNEXPECTED(value == NULL)) { + value = zend_hash_add_new(&EG(symbol_table).ht, Z_STR_P(varname), &EG(uninitialized_zval)); + idx = ((char*)value - (char*)EG(symbol_table).ht.arData) / sizeof(Bucket); + CACHE_PTR(Z_CACHE_SLOT_P(varname), (void*)(uintptr_t)idx); + } else { + idx = ((char*)value - (char*)EG(symbol_table).ht.arData) / sizeof(Bucket); + CACHE_PTR(Z_CACHE_SLOT_P(varname), (void*)(uintptr_t)idx); + /* GLOBAL variable may be an INDIRECT pointer to CV */ + if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + value = Z_INDIRECT_P(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + ZVAL_NULL(value); + } + } } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 1a2defd584..d2afba6272 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -4686,7 +4686,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -5747,7 +5747,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -7080,7 +7080,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -8887,7 +8887,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -11280,7 +11280,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -12265,7 +12265,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -13555,7 +13555,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -15124,7 +15124,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -19219,7 +19219,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -21201,7 +21201,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -23552,7 +23552,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -26776,7 +26776,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -28242,7 +28242,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -29527,7 +29527,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -30814,7 +30814,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -32610,7 +32610,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -36193,7 +36193,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -36402,19 +36402,46 @@ static int ZEND_FASTCALL ZEND_BIND_GLOBAL_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HAN zval *varname; zval *value; zval *variable_ptr; - zend_string *name; + Bucket *p; + uint32_t idx; SAVE_OPLINE(); varname = opline->op2.zv; - name = Z_STR_P(varname); - value = zend_hash_find(&EG(symbol_table).ht, name); - if (value == NULL) { - value = zend_hash_add_new(&EG(symbol_table).ht, name, &EG(uninitialized_zval)); + idx = (uint32_t)(uintptr_t)CACHED_PTR(Z_CACHE_SLOT_P(varname)); + /* index 0 can't be cached (NULL is a mark of uninitialized cache slot) */ + p = EG(symbol_table).ht.arData + idx; + if (EXPECTED(idx > 0) && + EXPECTED(idx < EG(symbol_table).ht.nNumUsed) && + EXPECTED(Z_TYPE(p->val) != IS_UNDEF) && + (EXPECTED(p->key == Z_STR_P(varname)) || + (EXPECTED(p->h == Z_STR_P(varname)->h) && + EXPECTED(p->key != NULL) && + EXPECTED(p->key->len == Z_STRLEN_P(varname)) && + EXPECTED(memcmp(p->key->val, Z_STRVAL_P(varname), Z_STRLEN_P(varname)) == 0)))) { + value = &EG(symbol_table).ht.arData[idx].val; /* GLOBAL variable may be an INDIRECT pointer to CV */ - } else if (Z_TYPE_P(value) == IS_INDIRECT) { - value = Z_INDIRECT_P(value); - if (Z_TYPE_P(value) == IS_UNDEF) { - ZVAL_NULL(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + value = Z_INDIRECT_P(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + ZVAL_NULL(value); + } + } + } else { + value = zend_hash_find(&EG(symbol_table).ht, Z_STR_P(varname)); + if (UNEXPECTED(value == NULL)) { + value = zend_hash_add_new(&EG(symbol_table).ht, Z_STR_P(varname), &EG(uninitialized_zval)); + idx = ((char*)value - (char*)EG(symbol_table).ht.arData) / sizeof(Bucket); + CACHE_PTR(Z_CACHE_SLOT_P(varname), (void*)(uintptr_t)idx); + } else { + idx = ((char*)value - (char*)EG(symbol_table).ht.arData) / sizeof(Bucket); + CACHE_PTR(Z_CACHE_SLOT_P(varname), (void*)(uintptr_t)idx); + /* GLOBAL variable may be an INDIRECT pointer to CV */ + if (UNEXPECTED(Z_TYPE_P(value) == IS_INDIRECT)) { + value = Z_INDIRECT_P(value); + if (UNEXPECTED(Z_TYPE_P(value) == IS_UNDEF)) { + ZVAL_NULL(value); + } + } } } @@ -38086,7 +38113,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -40317,7 +40344,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; @@ -43285,7 +43312,7 @@ num_index_prop: } } if (Z_TYPE_P(offset) == IS_LONG) { - if (offset->value.lval >= 0 && offset->value.lval < (zend_long)Z_STRLEN_P(container)) { + if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) { if ((opline->extended_value & ZEND_ISSET) || Z_STRVAL_P(container)[offset->value.lval] != '0') { result = 1; diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index ac2374c6a3..490a92618d 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -824,16 +824,16 @@ static php_iconv_err_t _php_iconv_substr(smart_str *pretval, } } - if(len > (zend_long)total_len) { + if((size_t)len > total_len) { len = total_len; } - if (offset >= (zend_long)total_len) { + if ((size_t)offset >= total_len) { return PHP_ICONV_ERR_SUCCESS; } - if ((offset + len) > (zend_long)total_len ) { + if ((size_t)(offset + len) > total_len ) { /* trying to compute the length */ len = total_len - offset; } diff --git a/ext/json/utf8_decode.h b/ext/json/utf8_decode.h index cc0fc79f6c..0908edd2d4 100644 --- a/ext/json/utf8_decode.h +++ b/ext/json/utf8_decode.h @@ -5,8 +5,8 @@ typedef struct json_utf8_decode { - int the_index; char *the_input; + int the_index; int the_length; int the_char; int the_byte; diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 212c8d013f..615381e6c4 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2963,7 +2963,7 @@ PHP_FUNCTION(mb_strimwidth) string.val = (unsigned char *)str; string.len = str_len; - if (from < 0 || from > str_len) { + if (from < 0 || (size_t)from > str_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Start position is out of range"); RETURN_FALSE; } diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c index 9628ee2526..864d50a5ce 100644 --- a/ext/mbstring/php_mbregex.c +++ b/ext/mbstring/php_mbregex.c @@ -1081,7 +1081,7 @@ PHP_FUNCTION(mb_split) err = 0; regs = onig_region_new(); /* churn through str, generating array entries as we go */ - while (count != 0 && (pos - (OnigUChar *)string) < string_len) { + while (count != 0 && (pos - (OnigUChar *)string) < (ptrdiff_t)string_len) { int beg, end; err = onig_search(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), pos, (OnigUChar *)(string + string_len), regs, 0); if (err < 0) { @@ -1403,7 +1403,7 @@ PHP_FUNCTION(mb_ereg_search_setpos) return; } - if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && position >= Z_STRLEN(MBREX(search_str)))) { + if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && (size_t)position >= Z_STRLEN(MBREX(search_str)))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position is out of range"); MBREX(search_pos) = 0; RETURN_FALSE; diff --git a/ext/mysqlnd/mysqlnd.c b/ext/mysqlnd/mysqlnd.c index 74a8b721f2..20972f64be 100644 --- a/ext/mysqlnd/mysqlnd.c +++ b/ext/mysqlnd/mysqlnd.c @@ -2798,7 +2798,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, tx_begin)(MYSQLND_CONN_DATA * conn, const unsi smart_str_appendl(&tmp_str, "WITH CONSISTENT SNAPSHOT", sizeof("WITH CONSISTENT SNAPSHOT") - 1); } if (mode & (TRANS_START_READ_WRITE | TRANS_START_READ_ONLY)) { - unsigned long server_version = conn->m->get_server_version(conn TSRMLS_CC); + zend_ulong server_version = conn->m->get_server_version(conn TSRMLS_CC); if (server_version < 50605L) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required"); smart_str_free(&tmp_str); diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c index 28e7a11314..091437e119 100644 --- a/ext/opcache/Optimizer/compact_literals.c +++ b/ext/opcache/Optimizer/compact_literals.c @@ -40,6 +40,7 @@ #define LITERAL_STATIC_PROPERTY 0x0700 #define LITERAL_METHOD 0x0800 #define LITERAL_PROPERTY 0x0900 +#define LITERAL_GLOBAL 0x0A00 #define LITERAL_EX_CLASS 0x4000 #define LITERAL_EX_OBJ 0x2000 @@ -278,6 +279,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx } } break; + case ZEND_BIND_GLOBAL: + LITERAL_INFO(opline->op2.constant, LITERAL_GLOBAL, 0, 1, 1); + break; default: if (ZEND_OP1_TYPE(opline) == IS_CONST) { LITERAL_INFO(opline->op1.constant, LITERAL_VALUE, 1, 0, 1); diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 0db82c6068..11b91e778f 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -406,10 +406,10 @@ yy45: struct placeholder { char *pos; + char *quoted; /* quoted value */ int len; int bindno; int qlen; /* quoted length of value */ - char *quoted; /* quoted value */ int freeq; struct placeholder *next; }; diff --git a/ext/session/session.c b/ext/session/session.c index de8cf23310..63463d487b 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1268,7 +1268,8 @@ static void php_session_remove_cookie(TSRMLS_D) { zend_llist_element *current; char *session_cookie; zend_string *e_session_name; - int session_cookie_len, len = sizeof("Set-Cookie")-1; + int session_cookie_len; + uint len = sizeof("Set-Cookie")-1; e_session_name = php_url_encode(PS(session_name), strlen(PS(session_name))); spprintf(&session_cookie, 0, "Set-Cookie: %s=", e_session_name->val); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 0694e8f335..293be0b0dd 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -2883,7 +2883,12 @@ SPL_METHOD(SplFileObject, fwrite) } if (ZEND_NUM_ARGS() > 1) { - str_len = MAX(0, MIN(length, str_len)); + if (length >= 0) { + str_len = MAX(0, MIN((size_t)length, str_len)); + } else { + /* Negative length given, nothing to write */ + str_len = 0; + } } if (!str_len) { RETURN_LONG(0); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index e02b9b2e83..1bd4bf49d5 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -101,8 +101,8 @@ struct _spl_dllist_object { /* define an overloaded iterator structure */ struct _spl_dllist_it { zend_user_iterator intern; - int traverse_position; spl_ptr_llist_element *traverse_pointer; + int traverse_position; int flags; }; diff --git a/ext/standard/array.c b/ext/standard/array.c index 09aaddfbf5..a417925528 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1528,7 +1528,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu PHP_FUNCTION(compact) { zval *args = NULL; /* function arguments array */ - int num_args, i; + uint32_t num_args, i; zend_array *symbol_table; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) { @@ -2085,7 +2085,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end) zend_hash_rehash(Z_ARRVAL_P(stack)); } } - } else if (!key && Z_ARRVAL_P(stack)->nNextFreeElement > 0 && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) { + } else if (!key && Z_ARRVAL_P(stack)->nNextFreeElement > 0 && index >= (zend_ulong)(Z_ARRVAL_P(stack)->nNextFreeElement - 1)) { Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1; } @@ -3174,7 +3174,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int int arr_argc, i, c = 0; uint idx; Bucket **lists, *list, **ptrs, *p; - int req_args; + uint32_t req_args; char *param_spec; zend_fcall_info fci1, fci2; zend_fcall_info_cache fci1_cache = empty_fcall_info_cache, fci2_cache = empty_fcall_info_cache; @@ -3598,7 +3598,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ int arr_argc, i, c; uint idx; Bucket **lists, *list, **ptrs, *p; - int req_args; + uint32_t req_args; char *param_spec; zend_fcall_info fci1, fci2; zend_fcall_info_cache fci1_cache = empty_fcall_info_cache, fci2_cache = empty_fcall_info_cache; @@ -4423,7 +4423,8 @@ PHP_FUNCTION(array_map) zval result; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; - int i, k, maxlen = 0; + int i; + uint32_t k, maxlen = 0; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!+", &fci, &fci_cache, &arrays, &n_arrays) == FAILURE) { diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index de4d71106b..53aec268b0 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4178,8 +4178,9 @@ static int parse_opts(char * opts, opt_struct ** result) { opt_struct * paras = NULL; unsigned int i, count = 0; + unsigned int opts_len = (unsigned int)strlen(opts); - for (i = 0; i < strlen(opts); i++) { + for (i = 0; i < opts_len; i++) { if ((opts[i] >= 48 && opts[i] <= 57) || (opts[i] >= 65 && opts[i] <= 90) || (opts[i] >= 97 && opts[i] <= 122) diff --git a/ext/standard/info.c b/ext/standard/info.c index 286ea5c2cb..e74772da39 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -219,7 +219,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) php_info_print(string_key->val); } } else { - php_info_printf("%pd", num_key); + php_info_printf(ZEND_ULONG_FMT, num_key); } php_info_print("\"]"); if (!sapi_module.phpinfo_as_text) { diff --git a/ext/standard/string.c b/ext/standard/string.c index 0c41249473..c01259b85e 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -780,7 +780,7 @@ static inline int php_charmask(unsigned char *input, size_t len, char *mask TSRM */ PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *return_value, int mode TSRMLS_DC) { - register zend_long i; + register size_t i; size_t trimmed = 0; char mask[256]; @@ -802,12 +802,15 @@ PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *re c += trimmed; } if (mode & 2) { - for (i = len - 1; i >= 0; i--) { - if (mask[(unsigned char)c[i]]) { - len--; - } else { - break; - } + if (len > 0) { + i = len - 1; + do { + if (mask[(unsigned char)c[i]]) { + len--; + } else { + break; + } + } while (i-- != 0); } } @@ -1810,7 +1813,7 @@ PHP_FUNCTION(strpos) ZEND_PARSE_PARAMETERS_END(); #endif - if (offset < 0 || offset > haystack->len) { + if (offset < 0 || (size_t)offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } @@ -1860,7 +1863,7 @@ PHP_FUNCTION(stripos) return; } - if (offset < 0 || offset > haystack->len) { + if (offset < 0 || (size_t)offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } @@ -1948,20 +1951,20 @@ PHP_FUNCTION(strrpos) } if (offset >= 0) { - if (offset > haystack->len) { + if ((size_t)offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } - p = haystack->val + offset; + p = haystack->val + (size_t)offset; e = haystack->val + haystack->len - needle_len; } else { - if (offset < -INT_MAX || -offset > haystack->len) { + if (offset < -INT_MAX || (size_t)(-offset) > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = haystack->val; - if (needle_len > -offset) { + if (needle_len > (size_t)(-offset)) { e = haystack->val + haystack->len - needle_len; } else { e = haystack->val + haystack->len + offset; @@ -2026,7 +2029,7 @@ PHP_FUNCTION(strripos) /* Single character search can shortcut memcmps Can also avoid tolower emallocs */ if (offset >= 0) { - if (offset > haystack->len) { + if ((size_t)offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } @@ -2034,7 +2037,7 @@ PHP_FUNCTION(strripos) e = haystack->val + haystack->len - 1; } else { p = haystack->val; - if (offset < -INT_MAX || -offset > haystack->len) { + if (offset < -INT_MAX || (size_t)(-offset) > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } @@ -2057,7 +2060,7 @@ PHP_FUNCTION(strripos) php_strtolower(haystack_dup, haystack->len); if (offset >= 0) { - if (offset > haystack->len) { + if ((size_t)offset > haystack->len) { efree(needle_dup); efree(haystack_dup); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); @@ -2066,14 +2069,14 @@ PHP_FUNCTION(strripos) p = haystack_dup + offset; e = haystack_dup + haystack->len - needle_len; } else { - if (offset < -INT_MAX || -offset > haystack->len) { + if (offset < -INT_MAX || (size_t)(-offset) > haystack->len) { efree(needle_dup); efree(haystack_dup); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = haystack_dup; - if (needle_len > -offset) { + if (needle_len > (size_t)(-offset)) { e = haystack_dup + haystack->len - needle_len; } else { e = haystack_dup + haystack->len + offset; @@ -2197,7 +2200,7 @@ PHP_FUNCTION(chunk_split) RETURN_FALSE; } - if (chunklen > str->len) { + if ((size_t)chunklen > str->len) { /* to maintain BC, we must return original string + ending */ result = zend_string_alloc(endlen + str->len, 0); memcpy(result->val, str->val, str->len); @@ -2210,7 +2213,7 @@ PHP_FUNCTION(chunk_split) RETURN_EMPTY_STRING(); } - result = php_chunk_split(str->val, str->len, end, endlen, chunklen); + result = php_chunk_split(str->val, str->len, end, endlen, (size_t)chunklen); if (result) { RETURN_STR(result); @@ -2242,7 +2245,7 @@ PHP_FUNCTION(substr) #endif if (argc > 2) { - if ((l < 0 && -l > str->len)) { + if ((l < 0 && (size_t)(-l) > str->len)) { RETURN_FALSE; } else if (l > (zend_long)str->len) { l = str->len; @@ -3794,7 +3797,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit zval result; zend_string *string_key; zend_ulong num_key; - zend_long count = 0; + size_t count = 0; int argc = ZEND_NUM_ARGS(); #ifndef FAST_ZPP @@ -4999,7 +5002,7 @@ PHP_FUNCTION(substr_count) RETURN_FALSE; } - if (offset > haystack_len) { + if ((size_t)offset > haystack_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset value " ZEND_LONG_FMT " exceeds string length", offset); RETURN_FALSE; } @@ -5058,7 +5061,7 @@ PHP_FUNCTION(str_pad) /* If resulting string turns out to be shorter than input string, we simply copy the input and return. */ - if (pad_length < 0 || pad_length <= input->len) { + if (pad_length < 0 || (size_t)pad_length <= input->len) { RETURN_STRINGL(input->val, input->len); } @@ -5347,7 +5350,7 @@ PHP_FUNCTION(str_split) } - if (0 == str->len || split_length >= str->len) { + if (0 == str->len || (size_t)split_length >= str->len) { array_init_size(return_value, 1); add_next_index_stringl(return_value, str->val, str->len); return; @@ -5424,7 +5427,7 @@ PHP_FUNCTION(substr_compare) offset = (offset < 0) ? 0 : offset; } - if (offset >= s1->len) { + if ((size_t)offset >= s1->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } diff --git a/ext/zip/lib/zip_set_name.c b/ext/zip/lib/zip_set_name.c index 02fa1272d6..4793c54534 100644 --- a/ext/zip/lib/zip_set_name.c +++ b/ext/zip/lib/zip_set_name.c @@ -58,7 +58,7 @@ _zip_set_name(struct zip *za, zip_uint64_t idx, const char *name, zip_flags_t fl return -1; } - if (name && strlen(name) > 0) { + if (name && name[0] != '\0') { /* TODO: check for string too long */ if ((str=_zip_string_new((const zip_uint8_t *)name, (zip_uint16_t)strlen(name), flags, &za->error)) == NULL) return -1; diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 53bc2e4269..29377d8e99 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -25,12 +25,12 @@ /* Passed as opaque in malloc callbacks */ typedef struct _php_zlib_filter_data { - int persistent; z_stream strm; char *inbuf; size_t inbuf_len; char *outbuf; size_t outbuf_len; + int persistent; zend_bool finished; } php_zlib_filter_data; |