diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c index f038c9e8a984..9ca8b60f6c45 100644 --- a/Zend/Optimizer/block_pass.c +++ b/Zend/Optimizer/block_pass.c @@ -1125,7 +1125,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op /* adjust exception jump targets & remove unused try_catch_array entries */ if (op_array->last_try_catch) { - int i, j; + uint32_t i, j; uint32_t *map; ALLOCA_FLAG(use_heap); @@ -1165,7 +1165,7 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op while (opline < end) { if (opline->opcode == ZEND_FAST_RET && opline->op2.num != (uint32_t)-1 && - opline->op2.num < (uint32_t)j) { + opline->op2.num < j) { opline->op2.num = map[opline->op2.num]; } opline++; diff --git a/Zend/Optimizer/compact_literals.c b/Zend/Optimizer/compact_literals.c index d0aaccec7ce2..a2fa32994fee 100644 --- a/Zend/Optimizer/compact_literals.c +++ b/Zend/Optimizer/compact_literals.c @@ -110,7 +110,7 @@ static zend_string *create_str_cache_key(zval *literal, uint8_t num_related) void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx *ctx) { zend_op *opline, *end; - int i, j, n, *map; + int n, *map; uint32_t cache_size; zval zv, *pos; literal_info *info; @@ -124,6 +124,7 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx int *const_slot, *class_slot, *func_slot, *bind_var_slot, *property_slot, *method_slot, *jmp_slot; if (op_array->last_literal) { + uint32_t j; info = (literal_info*)zend_arena_calloc(&ctx->arena, op_array->last_literal, sizeof(literal_info)); /* Mark literals of specific types */ @@ -258,9 +259,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx op_array->function_name ? op_array->function_name->val : "main"); fprintf(stderr, "Literals table size %d\n", op_array->last_literal); - for (int i = 0; i < op_array->last_literal; i++) { + for (uint32_t i = 0; i < op_array->last_literal; i++) { zend_string *str = zval_get_string(op_array->literals + i); - fprintf(stderr, "Literal %d, val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str)); + fprintf(stderr, "Literal %" PRIu32 ", val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str)); zend_string_release(str); } fflush(stderr); @@ -272,7 +273,7 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx zend_hash_init(&hash, op_array->last_literal, NULL, NULL, 0); map = (int*)zend_arena_alloc(&ctx->arena, op_array->last_literal * sizeof(int)); memset(map, 0, op_array->last_literal * sizeof(int)); - for (i = 0; i < op_array->last_literal; i++) { + for (uint32_t i = 0; i < op_array->last_literal; i++) { if (!info[i].num_related) { /* unset literal */ zval_ptr_dtor_nogc(&op_array->literals[i]); @@ -770,9 +771,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx { fprintf(stderr, "Optimized literals table size %d\n", op_array->last_literal); - for (int i = 0; i < op_array->last_literal; i++) { + for (uint32_t i = 0; i < op_array->last_literal; i++) { zend_string *str = zval_get_string(op_array->literals + i); - fprintf(stderr, "Literal %d, val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str)); + fprintf(stderr, "Literal %" PRIu32 ", val (%zu):%s\n", i, ZSTR_LEN(str), ZSTR_VAL(str)); zend_string_release(str); } fflush(stderr); diff --git a/Zend/Optimizer/dfa_pass.c b/Zend/Optimizer/dfa_pass.c index b64f6d8fa817..796e998493d7 100644 --- a/Zend/Optimizer/dfa_pass.c +++ b/Zend/Optimizer/dfa_pass.c @@ -226,7 +226,7 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op } /* update try/catch array */ - for (j = 0; j < op_array->last_try_catch; j++) { + for (uint32_t j = 0; j < op_array->last_try_catch; j++) { op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op]; op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op]; if (op_array->try_catch_array[j].finally_op) { diff --git a/Zend/Optimizer/nop_removal.c b/Zend/Optimizer/nop_removal.c index fd5a87cbfb28..c39c4bb1e4ff 100644 --- a/Zend/Optimizer/nop_removal.c +++ b/Zend/Optimizer/nop_removal.c @@ -34,7 +34,6 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx { zend_op *end, *opline; uint32_t new_count, i, shift; - int j; uint32_t *shiftlist; ALLOCA_FLAG(use_heap); @@ -81,7 +80,7 @@ void zend_optimizer_nop_removal(zend_op_array *op_array, zend_optimizer_ctx *ctx } /* update try/catch array */ - for (j = 0; j < op_array->last_try_catch; j++) { + for (uint32_t j = 0; j < op_array->last_try_catch; j++) { op_array->try_catch_array[j].try_op -= shiftlist[op_array->try_catch_array[j].try_op]; op_array->try_catch_array[j].catch_op -= shiftlist[op_array->try_catch_array[j].catch_op]; if (op_array->try_catch_array[j].finally_op) { diff --git a/Zend/Optimizer/zend_cfg.c b/Zend/Optimizer/zend_cfg.c index d2c54c913196..32d5f49ef7df 100644 --- a/Zend/Optimizer/zend_cfg.c +++ b/Zend/Optimizer/zend_cfg.c @@ -274,7 +274,6 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, { uint32_t flags = 0; uint32_t i; - int j; uint32_t *block_map; zend_function *fn; int blocks_count = 0; @@ -449,7 +448,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, } if (op_array->last_try_catch) { - for (j = 0; j < op_array->last_try_catch; j++) { + for (uint32_t j = 0; j < op_array->last_try_catch; j++) { BB_START(op_array->try_catch_array[j].try_op); if (op_array->try_catch_array[j].catch_op) { BB_START(op_array->try_catch_array[j].catch_op); @@ -494,7 +493,7 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, blocks_count++; /* Build CFG, Step 3: Calculate successors */ - for (j = 0; j < blocks_count; j++) { + for (int j = 0; j < blocks_count; j++) { zend_basic_block *block = &blocks[j]; zend_op *opline; if (block->len == 0) { diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c index 4b7ca1615a86..9c51ad223e06 100644 --- a/Zend/Optimizer/zend_dump.c +++ b/Zend/Optimizer/zend_dump.c @@ -1056,7 +1056,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) { fprintf(stderr, "LIVE RANGES:\n"); - for (int i = 0; i < op_array->last_live_range; i++) { + for (uint32_t i = 0; i < op_array->last_live_range; i++) { fprintf(stderr, " %u: %04u - %04u ", EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK), @@ -1083,7 +1083,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_try_catch) { fprintf(stderr, "EXCEPTION TABLE:\n"); - for (int i = 0; i < op_array->last_try_catch; i++) { + for (uint32_t i = 0; i < op_array->last_try_catch; i++) { fprintf(stderr, " BB%u", cfg->map[op_array->try_catch_array[i].try_op]); if (op_array->try_catch_array[i].catch_op) { @@ -1116,7 +1116,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_live_range && (dump_flags & ZEND_DUMP_LIVE_RANGES)) { fprintf(stderr, "LIVE RANGES:\n"); - for (int i = 0; i < op_array->last_live_range; i++) { + for (uint32_t i = 0; i < op_array->last_live_range; i++) { fprintf(stderr, " %u: %04u - %04u ", EX_VAR_TO_NUM(op_array->live_range[i].var & ~ZEND_LIVE_MASK), @@ -1143,7 +1143,7 @@ ZEND_API void zend_dump_op_array(const zend_op_array *op_array, uint32_t dump_fl } if (op_array->last_try_catch) { fprintf(stderr, "EXCEPTION TABLE:\n"); - for (int i = 0; i < op_array->last_try_catch; i++) { + for (uint32_t i = 0; i < op_array->last_try_catch; i++) { fprintf(stderr, " %04u", op_array->try_catch_array[i].try_op); diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c index 4e5ecca8a0f8..a206238b552b 100644 --- a/Zend/Optimizer/zend_optimizer.c +++ b/Zend/Optimizer/zend_optimizer.c @@ -210,9 +210,9 @@ void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline } } -int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv) +uint32_t zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv) { - int i = op_array->last_literal; + uint32_t i = op_array->last_literal; op_array->last_literal++; op_array->literals = (zval*)erealloc(op_array->literals, op_array->last_literal * sizeof(zval)); ZVAL_COPY_VALUE(&op_array->literals[i], zv); @@ -220,7 +220,7 @@ int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv) return i; } -static inline int zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) { +static inline uint32_t zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) { zval zv; ZVAL_STR(&zv, str); zend_string_hash_val(str); diff --git a/Zend/Optimizer/zend_optimizer_internal.h b/Zend/Optimizer/zend_optimizer_internal.h index 896fe8fb4728..9c238690932e 100644 --- a/Zend/Optimizer/zend_optimizer_internal.h +++ b/Zend/Optimizer/zend_optimizer_internal.h @@ -79,7 +79,7 @@ static inline bool zend_optimizer_is_loop_var_free(const zend_op *opline) { } void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline); -int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv); +uint32_t zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv); bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy); void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value); bool zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d0ce85dd3c6f..358b6723e005 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -536,7 +536,7 @@ static zend_always_inline uint32_t get_temporary_variable(void) /* {{{ */ } /* }}} */ -static int lookup_cv(zend_string *name) /* {{{ */{ +static uint32_t lookup_cv(zend_string *name) /* {{{ */{ zend_op_array *op_array = CG(active_op_array); int i = 0; zend_ulong hash_value = zend_string_hash_val(name); @@ -588,7 +588,7 @@ static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int li static int zend_add_literal(zval *zv) /* {{{ */ { zend_op_array *op_array = CG(active_op_array); - int i = op_array->last_literal; + uint32_t i = op_array->last_literal; op_array->last_literal++; if (i >= CG(context).literals_size) { while (i >= CG(context).literals_size) { @@ -5886,7 +5886,7 @@ static void zend_compile_break_continue(zend_ast *ast) /* {{{ */ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */ { zend_label *dest; - int current, remove_oplines = opline->op1.num; + int remove_oplines = opline->op1.num; zval *label; uint32_t opnum = opline - op_array->opcodes; @@ -5903,7 +5903,7 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */ zval_ptr_dtor_str(label); ZVAL_NULL(label); - current = opline->extended_value; + uint32_t current = opline->extended_value; for (; current != dest->brk_cont; current = CG(context).brk_cont_array[current].parent) { if (current == -1) { CG(in_compilation) = 1; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index c815248f7807..ab90b2dcaa83 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -197,8 +197,8 @@ typedef struct _zend_oparray_context { struct _zend_oparray_context *prev; zend_op_array *op_array; uint32_t opcodes_size; - int vars_size; - int literals_size; + uint32_t vars_size; + uint32_t literals_size; uint32_t fast_call_var; uint32_t try_catch_offset; int current_brk_cont; @@ -530,9 +530,9 @@ struct _zend_op_array { const zend_property_info *prop_info; /* The corresponding prop_info if this is a hook. */ /* END of common elements */ - int cache_size; /* number of run_time_cache_slots * sizeof(void*) */ - int last_var; /* number of CV variables */ - uint32_t last; /* number of opcodes */ + uint32_t cache_size; /* number of run_time_cache_slots * sizeof(void*) */ + int last_var; /* number of CV variables */ + uint32_t last; /* number of opcodes */ zend_op *opcodes; ZEND_MAP_PTR_DEF(HashTable *, static_variables_ptr); @@ -541,8 +541,8 @@ struct _zend_op_array { uint32_t *refcount; - int last_live_range; - int last_try_catch; + uint32_t last_live_range; + uint32_t last_try_catch; zend_live_range *live_range; zend_try_catch_element *try_catch_array; @@ -550,7 +550,7 @@ struct _zend_op_array { uint32_t line_start; uint32_t line_end; - int last_literal; + uint32_t last_literal; uint32_t num_dynamic_func_defs; zval *literals; diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index d5c9b1b1e313..13f1887027c8 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -244,7 +244,6 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */ zend_generator *current_generator = zend_generator_get_current(generator); zend_execute_data *ex = generator->execute_data; uint32_t op_num, try_catch_offset; - int i; /* If current_generator is running in a fiber, there are 2 cases to consider: * - If generator is also marked with ZEND_GENERATOR_IN_FIBER, then the @@ -289,7 +288,7 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */ try_catch_offset = -1; /* Find the innermost try/catch that we are inside of. */ - for (i = 0; i < ex->func->op_array.last_try_catch; i++) { + for (uint32_t i = 0; i < ex->func->op_array.last_try_catch; i++) { zend_try_catch_element *try_catch = &ex->func->op_array.try_catch_array[i]; if (op_num < try_catch->try_op) { break; diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index 43c6efb9107a..bf02d6a4164b 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -686,9 +686,7 @@ static void zend_extension_op_array_handler(zend_extension *extension, zend_op_a static void zend_check_finally_breakout(zend_op_array *op_array, uint32_t op_num, uint32_t dst_num) { - int i; - - for (i = 0; i < op_array->last_try_catch; i++) { + for (uint32_t i = 0; i < op_array->last_try_catch; i++) { if ((op_num < op_array->try_catch_array[i].finally_op || op_num >= op_array->try_catch_array[i].finally_end) && (dst_num >= op_array->try_catch_array[i].finally_op && diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 3ebf816cf381..b90117e70f22 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -8164,7 +8164,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY) } uint32_t throw_op_num = throw_op - EX(func)->op_array.opcodes; - int i, current_try_catch_offset = -1; + uint32_t current_try_catch_offset = -1; if ((throw_op->opcode == ZEND_FREE || throw_op->opcode == ZEND_FE_FREE) && throw_op->extended_value & ZEND_FREE_ON_RETURN) { @@ -8175,7 +8175,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY) const zend_live_range *range = find_live_range( &EX(func)->op_array, throw_op_num, throw_op->op1.var); /* free op1 of the corresponding RETURN */ - for (i = throw_op_num; i < range->end; i++) { + for (uint32_t i = throw_op_num; i < range->end; i++) { if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE || EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) { /* pass */ @@ -8191,7 +8191,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY) } /* Find the innermost try/catch/finally the exception was thrown in */ - for (i = 0; i < EX(func)->op_array.last_try_catch; i++) { + for (uint32_t i = 0; i < EX(func)->op_array.last_try_catch; i++) { zend_try_catch_element *try_catch = &EX(func)->op_array.try_catch_array[i]; if (try_catch->try_op > throw_op_num) { /* further blocks will not be relevant... */ diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index b0d6f2bc33d9..9d940cfadbcb 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -3392,7 +3392,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_HANDLE_EXCEPT } uint32_t throw_op_num = throw_op - EX(func)->op_array.opcodes; - int i, current_try_catch_offset = -1; + uint32_t current_try_catch_offset = -1; if ((throw_op->opcode == ZEND_FREE || throw_op->opcode == ZEND_FE_FREE) && throw_op->extended_value & ZEND_FREE_ON_RETURN) { @@ -3403,7 +3403,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_HANDLE_EXCEPT const zend_live_range *range = find_live_range( &EX(func)->op_array, throw_op_num, throw_op->op1.var); /* free op1 of the corresponding RETURN */ - for (i = throw_op_num; i < range->end; i++) { + for (uint32_t i = throw_op_num; i < range->end; i++) { if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE || EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) { /* pass */ @@ -3419,7 +3419,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_HANDLE_EXCEPT } /* Find the innermost try/catch/finally the exception was thrown in */ - for (i = 0; i < EX(func)->op_array.last_try_catch; i++) { + for (uint32_t i = 0; i < EX(func)->op_array.last_try_catch; i++) { zend_try_catch_element *try_catch = &EX(func)->op_array.try_catch_array[i]; if (try_catch->try_op > throw_op_num) { /* further blocks will not be relevant... */ @@ -58815,7 +58815,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_HANDLE_EXCEPTION_S } uint32_t throw_op_num = throw_op - EX(func)->op_array.opcodes; - int i, current_try_catch_offset = -1; + uint32_t current_try_catch_offset = -1; if ((throw_op->opcode == ZEND_FREE || throw_op->opcode == ZEND_FE_FREE) && throw_op->extended_value & ZEND_FREE_ON_RETURN) { @@ -58826,7 +58826,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_HANDLE_EXCEPTION_S const zend_live_range *range = find_live_range( &EX(func)->op_array, throw_op_num, throw_op->op1.var); /* free op1 of the corresponding RETURN */ - for (i = throw_op_num; i < range->end; i++) { + for (uint32_t i = throw_op_num; i < range->end; i++) { if (EX(func)->op_array.opcodes[i].opcode == ZEND_FREE || EX(func)->op_array.opcodes[i].opcode == ZEND_FE_FREE) { /* pass */ @@ -58842,7 +58842,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_HANDLE_EXCEPTION_S } /* Find the innermost try/catch/finally the exception was thrown in */ - for (i = 0; i < EX(func)->op_array.last_try_catch; i++) { + for (uint32_t i = 0; i < EX(func)->op_array.last_try_catch; i++) { zend_try_catch_element *try_catch = &EX(func)->op_array.try_catch_array[i]; if (try_catch->try_op > throw_op_num) { /* further blocks will not be relevant... */ diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 491f59b2bce3..a6af7469cbac 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -1306,11 +1306,14 @@ PHP_FUNCTION(odbc_exec) } /* }}} */ -#define ODBC_NUM 1 -#define ODBC_OBJECT 2 +typedef enum php_odbc_fetch_result_type_t { + ODBC_NONE = 0, + ODBC_NUM = 1, + ODBC_OBJECT = 2, +} php_odbc_fetch_result_type_t; -/* {{{ php_odbc_fetch_hash */ -static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) +/* {{{ php_odbc_fetch */ +static void php_odbc_fetch(INTERNAL_FUNCTION_PARAMETERS, bool return_array, php_odbc_fetch_result_type_t result_type) { int i; odbc_result *result; @@ -1319,29 +1322,56 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) char *buf = NULL; zend_long pv_row = 0; bool pv_row_is_null = true; - zval *pv_res, tmp; - SQLULEN crow; - SQLUSMALLINT RowStatus[1]; + zval *pv_res, *pv_res_arr, tmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &pv_res, odbc_result_ce, &pv_row, &pv_row_is_null) == FAILURE) { - RETURN_THROWS(); + if (return_array || result_type == ODBC_NONE) { + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_OBJECT_OF_CLASS(pv_res, odbc_result_ce) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(pv_row, pv_row_is_null) + ZEND_PARSE_PARAMETERS_END(); + /* So we can use pv_res_arr for both return value and passed */ + pv_res_arr = return_value; + } else { + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_OBJECT_OF_CLASS(pv_res, odbc_result_ce) + Z_PARAM_ZVAL(pv_res_arr) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(pv_row, pv_row_is_null) + ZEND_PARSE_PARAMETERS_END(); } result = Z_ODBC_RESULT_P(pv_res); CHECK_ODBC_RESULT(result); - /* TODO deprecate $row argument values less than 1 after PHP 8.4 */ + /* TODO deprecate $row argument values less than 1 after PHP 8.4 + * for functions other than odbc_fetch_row (see GH-13910) + */ + if (!result_type && !pv_row_is_null && pv_row < 1) { + php_error_docref(NULL, E_WARNING, "Argument #3 ($row) must be greater than or equal to 1"); + RETURN_FALSE; + } if (result->numcols == 0) { php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } + /* If we're initializing a passed value into an array, do it before the fetch + * so that an empty result set will still be an array. + */ + if (!return_array && result_type) { + pv_res_arr = zend_try_array_init(pv_res_arr); + if (!pv_res_arr) { + RETURN_THROWS(); + } + } + if (result->fetch_abs) { if (!pv_row_is_null && pv_row > 0) { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_ABSOLUTE,(SQLLEN)pv_row,&crow,RowStatus); + rc = SQLFetchScroll(result->stmt, SQL_FETCH_ABSOLUTE, (SQLLEN)pv_row); } else { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); + rc = SQLFetchScroll(result->stmt, SQL_FETCH_NEXT, 1); } } else { rc = SQLFetch(result->stmt); @@ -1349,18 +1379,28 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLExtendedFetch"); + odbc_sql_error(result->conn_ptr, result->stmt, "SQLFetchScroll"); } RETURN_FALSE; } - array_init(return_value); + /* ...but if returning an array, init only if we have a result set */ + if (return_array && result_type) { + array_init(pv_res_arr); + } if (!pv_row_is_null && pv_row > 0 && result->fetch_abs) result->fetched = (SQLLEN)pv_row; else result->fetched++; + /* For fetch_row, we don't return anything other than true, + * odbc_result will be used to fetch values instead. + */ + if (result_type == ODBC_NONE) { + RETURN_TRUE; + } + for(i = 0; i < result->numcols; i++) { sql_c_type = SQL_C_CHAR; @@ -1375,6 +1415,8 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (result->binmode == 1) { sql_c_type = SQL_C_BINARY; } + + /* TODO: Check this is the intended behaviour */ ZEND_FALLTHROUGH; case SQL_LONGVARCHAR: case SQL_WLONGVARCHAR: @@ -1391,7 +1433,9 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) if (rc == SQL_ERROR) { odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData"); efree(buf); - zval_ptr_dtor(return_value); + if (return_array) { + zval_ptr_dtor(pv_res_arr); + } RETURN_FALSE; } @@ -1425,18 +1469,23 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) } if (result_type & ODBC_NUM) { - zend_hash_index_update(Z_ARRVAL_P(return_value), i, &tmp); + zend_hash_index_update(Z_ARRVAL_P(pv_res_arr), i, &tmp); } else { if (!*(result->values[i].name) && Z_TYPE(tmp) == IS_STRING) { - zend_hash_update(Z_ARRVAL_P(return_value), Z_STR(tmp), &tmp); + zend_hash_update(Z_ARRVAL_P(pv_res_arr), Z_STR(tmp), &tmp); } else { - zend_hash_str_update(Z_ARRVAL_P(return_value), result->values[i].name, strlen(result->values[i].name), &tmp); + zend_hash_str_update(Z_ARRVAL_P(pv_res_arr), result->values[i].name, strlen(result->values[i].name), &tmp); } } } if (buf) { efree(buf); } + + /* return_value was set to an array otherwise */ + if (!return_array) { + RETURN_LONG(result->numcols); + } } /* }}} */ @@ -1444,7 +1493,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) /* {{{ Fetch a result row as an object */ PHP_FUNCTION(odbc_fetch_object) { - php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, ODBC_OBJECT); + php_odbc_fetch(INTERNAL_FUNCTION_PARAM_PASSTHRU, true, ODBC_OBJECT); if (Z_TYPE_P(return_value) == IS_ARRAY) { object_and_properties_init(return_value, ZEND_STANDARD_CLASS_DEF_PTR, Z_ARRVAL_P(return_value)); } @@ -1454,184 +1503,21 @@ PHP_FUNCTION(odbc_fetch_object) /* {{{ Fetch a result row as an associative array */ PHP_FUNCTION(odbc_fetch_array) { - php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, ODBC_OBJECT); + php_odbc_fetch(INTERNAL_FUNCTION_PARAM_PASSTHRU, true, ODBC_OBJECT); } /* }}} */ /* {{{ Fetch one result row into an array */ PHP_FUNCTION(odbc_fetch_into) { - int i; - odbc_result *result; - RETCODE rc; - SQLSMALLINT sql_c_type; - char *buf = NULL; - zval *pv_res, *pv_res_arr, tmp; - zend_long pv_row = 0; - bool pv_row_is_null = true; - SQLULEN crow; - SQLUSMALLINT RowStatus[1]; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oz|l!", &pv_res, odbc_result_ce, &pv_res_arr, &pv_row, &pv_row_is_null) == FAILURE) { - RETURN_THROWS(); - } - - result = Z_ODBC_RESULT_P(pv_res); - CHECK_ODBC_RESULT(result); - - /* TODO deprecate $row argument values less than 1 after PHP 8.4 */ - - if (result->numcols == 0) { - php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); - RETURN_FALSE; - } - - pv_res_arr = zend_try_array_init(pv_res_arr); - if (!pv_res_arr) { - RETURN_THROWS(); - } - - if (result->fetch_abs) { - if (!pv_row_is_null && pv_row > 0) { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_ABSOLUTE,(SQLLEN)pv_row,&crow,RowStatus); - } else { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); - } - } else { - rc = SQLFetch(result->stmt); - } - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLExtendedFetch"); - } - RETURN_FALSE; - } - - if (!pv_row_is_null && pv_row > 0 && result->fetch_abs) - result->fetched = (SQLLEN)pv_row; - else - result->fetched++; - - for(i = 0; i < result->numcols; i++) { - sql_c_type = SQL_C_CHAR; - - switch(result->values[i].coltype) { - case SQL_BINARY: - case SQL_VARBINARY: - case SQL_LONGVARBINARY: - if (result->binmode <= 0) { - ZVAL_EMPTY_STRING(&tmp); - break; - } - if (result->binmode == 1) sql_c_type = SQL_C_BINARY; - - /* TODO: Check this is the intended behaviour */ - ZEND_FALLTHROUGH; - case SQL_LONGVARCHAR: - case SQL_WLONGVARCHAR: - if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) { - ZVAL_EMPTY_STRING(&tmp); - break; - } - - if (buf == NULL) { - buf = emalloc(result->longreadlen + 1); - } - rc = SQLGetData(result->stmt, (SQLUSMALLINT)(i + 1),sql_c_type, buf, result->longreadlen + 1, &result->values[i].vallen); - - if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData"); - efree(buf); - RETURN_FALSE; - } - if (rc == SQL_SUCCESS_WITH_INFO) { - ZVAL_STRINGL(&tmp, buf, result->longreadlen); - } else if (rc != SQL_SUCCESS) { - php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (retcode %u)", i + 1, rc); - ZVAL_FALSE(&tmp); - } else if (result->values[i].vallen == SQL_NULL_DATA) { - ZVAL_NULL(&tmp); - break; - } else if (result->values[i].vallen == SQL_NO_TOTAL) { - php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (driver cannot determine length)", i + 1); - ZVAL_FALSE(&tmp); - } else { - ZVAL_STRINGL(&tmp, buf, result->values[i].vallen); - } - break; - - default: - if (result->values[i].vallen == SQL_NULL_DATA) { - ZVAL_NULL(&tmp); - break; - } else if (result->values[i].vallen == SQL_NO_TOTAL) { - php_error_docref(NULL, E_WARNING, "Cannot get data of column #%d (driver cannot determine length)", i + 1); - ZVAL_FALSE(&tmp); - break; - } - ZVAL_STRINGL(&tmp, result->values[i].value, result->values[i].vallen); - break; - } - zend_hash_index_update(Z_ARRVAL_P(pv_res_arr), i, &tmp); - } - if (buf) efree(buf); - RETURN_LONG(result->numcols); + php_odbc_fetch(INTERNAL_FUNCTION_PARAM_PASSTHRU, false, ODBC_NUM); } /* }}} */ /* {{{ Fetch a row */ PHP_FUNCTION(odbc_fetch_row) { - odbc_result *result; - RETCODE rc; - zval *pv_res; - zend_long pv_row = 0; - bool pv_row_is_null = true; - SQLULEN crow; - SQLUSMALLINT RowStatus[1]; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!", &pv_res, odbc_result_ce, &pv_row, &pv_row_is_null) == FAILURE) { - RETURN_THROWS(); - } - - result = Z_ODBC_RESULT_P(pv_res); - CHECK_ODBC_RESULT(result); - - if (!pv_row_is_null && pv_row < 1) { - php_error_docref(NULL, E_WARNING, "Argument #3 ($row) must be greater than or equal to 1"); - RETURN_FALSE; - } - - if (result->numcols == 0) { - php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); - RETURN_FALSE; - } - - if (result->fetch_abs) { - if (!pv_row_is_null) { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_ABSOLUTE,(SQLLEN)pv_row,&crow,RowStatus); - } else { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); - } - } else { - rc = SQLFetch(result->stmt); - } - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLExtendedFetch"); - } - RETURN_FALSE; - } - - if (!pv_row_is_null) { - result->fetched = (SQLLEN)pv_row; - } else { - result->fetched++; - } - - RETURN_TRUE; + php_odbc_fetch(INTERNAL_FUNCTION_PARAM_PASSTHRU, false, ODBC_NONE); } /* }}} */ @@ -1648,8 +1534,6 @@ PHP_FUNCTION(odbc_result) RETCODE rc; SQLLEN fieldsize; zval *pv_res; - SQLULEN crow; - SQLUSMALLINT RowStatus[1]; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_OBJECT_OF_CLASS(pv_res, odbc_result_ce) @@ -1700,14 +1584,15 @@ PHP_FUNCTION(odbc_result) if (result->fetched == 0) { /* User forgot to call odbc_fetch_row(), or wants to reload the results, do it now */ - if (result->fetch_abs) - rc = SQLExtendedFetch(result->stmt, SQL_FETCH_NEXT, 1, &crow,RowStatus); - else + if (result->fetch_abs) { + rc = SQLFetchScroll(result->stmt, SQL_FETCH_NEXT, 1); + } else { rc = SQLFetch(result->stmt); + } if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { if (rc == SQL_ERROR) { - odbc_sql_error(result->conn_ptr, result->stmt, "SQLExtendedFetch"); + odbc_sql_error(result->conn_ptr, result->stmt, "SQLFetchScroll"); } RETURN_FALSE; } @@ -1850,8 +1735,6 @@ PHP_FUNCTION(odbc_result_all) char *pv_format = NULL; size_t i, pv_format_len = 0; SQLSMALLINT sql_c_type; - SQLULEN crow; - SQLUSMALLINT RowStatus[1]; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &pv_res, odbc_result_ce, &pv_format, &pv_format_len) == FAILURE) { RETURN_THROWS(); @@ -1864,10 +1747,11 @@ PHP_FUNCTION(odbc_result_all) php_error_docref(NULL, E_WARNING, "No tuples available at this result index"); RETURN_FALSE; } - if (result->fetch_abs) - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); - else + if (result->fetch_abs) { + rc = SQLFetchScroll(result->stmt, SQL_FETCH_NEXT, 1); + } else { rc = SQLFetch(result->stmt); + } if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { php_printf("

No rows found

\n"); @@ -1962,10 +1846,11 @@ PHP_FUNCTION(odbc_result_all) } php_printf("\n"); - if (result->fetch_abs) - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); - else + if (result->fetch_abs) { + rc = SQLFetchScroll(result->stmt, SQL_FETCH_NEXT, 1); + } else { rc = SQLFetch(result->stmt); + } } php_printf("\n"); if (buf) efree(buf); diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index 7e5eb6abbbc9..feede18999b9 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -1268,13 +1268,12 @@ static void zend_jit_allocate_registers(zend_jit_ctx *ctx, const zend_op_array * && ssa->vars[i].definition >= 0 && ssa->ops[op_num].result_def == i) { const zend_live_range *range = op_array->live_range; - int j; op_num++; if (op_array->opcodes[op_num].opcode == ZEND_OP_DATA) { op_num++; } - for (j = 0; j < op_array->last_live_range; range++, j++) { + for (uint32_t j = 0; j < op_array->last_live_range; range++, j++) { if (range->start > op_num) { /* further blocks will not be relevant... */ break; diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index 5e10237d62f1..9dc6ea1c3b00 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -6583,10 +6583,9 @@ static zend_vm_opcode_handler_t zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t var_num = opline->result.var; uint32_t op_num = opline - op_array->opcodes; const zend_live_range *range = op_array->live_range; - int j; op_num += zend_jit_trace_op_len(opline); - for (j = 0; j < op_array->last_live_range; range++, j++) { + for (uint32_t j = 0; j < op_array->last_live_range; range++, j++) { if (range->start > op_num) { /* further blocks will not be relevant... */ break; diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index b329bdac728b..9c93cd2b88ef 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -307,7 +307,7 @@ PHPDBG_INFO(literal) /* {{{ */ bool in_executor = PHPDBG_G(in_execution) && EG(current_execute_data) && EG(current_execute_data)->func; if (in_executor || PHPDBG_G(ops)) { zend_op_array *ops = in_executor ? &EG(current_execute_data)->func->op_array : PHPDBG_G(ops); - int literal = 0, count = ops->last_literal - 1; + uint32_t literal = 0, count = ops->last_literal - 1; if (ops->function_name) { if (ops->scope) { diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c index 329ee9a8830e..55d97acc3875 100644 --- a/sapi/phpdbg/phpdbg_utils.c +++ b/sapi/phpdbg/phpdbg_utils.c @@ -612,7 +612,7 @@ int phpdbg_is_auto_global(char *name, int len) { PHPDBG_API bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zend_object *exception) { const zend_op *op; zend_op *cur; - uint32_t op_num, i; + uint32_t op_num; zend_op_array *op_array = &execute_data->func->op_array; if (execute_data->opline >= EG(exception_op) && execute_data->opline < EG(exception_op) + 3 && EG(opline_before_exception)) { @@ -623,7 +623,7 @@ PHPDBG_API bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zend_obj op_num = op - op_array->opcodes; - for (i = 0; i < op_array->last_try_catch && op_array->try_catch_array[i].try_op <= op_num; i++) { + for (uint32_t i = 0; i < op_array->last_try_catch && op_array->try_catch_array[i].try_op <= op_num; i++) { uint32_t catch = op_array->try_catch_array[i].catch_op, finally = op_array->try_catch_array[i].finally_op; if (op_num <= catch || op_num <= finally) { if (finally) {