]> granicus.if.org Git - php/commitdiff
Avoid misc uninitialized variable warnings
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 12:55:37 +0000 (14:55 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Apr 2019 13:12:39 +0000 (15:12 +0200)
Zend/zend_compile.c
ext/mbstring/mbstring.c
ext/opcache/Optimizer/scdf.c
ext/opcache/Optimizer/zend_ssa.c
ext/pdo/pdo_stmt.c
ext/sqlite3/sqlite3.c
ext/standard/streamsfuncs.c
ext/standard/string.c

index 1294c1f488dbb0cc413ea5cabab5cd4602944cc1..0ef5469083413efc346feb449260a57efa7eceef 100644 (file)
@@ -4757,7 +4757,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
 
        znode expr_node, case_node;
        zend_op *opline;
-       uint32_t *jmpnz_opnums, opnum_default_jmp, opnum_switch;
+       uint32_t *jmpnz_opnums, opnum_default_jmp, opnum_switch = (uint32_t)-1;
        zend_uchar jumptable_type;
        HashTable *jumptable = NULL;
 
@@ -4850,6 +4850,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
                        zend_update_jump_target_to_next(opnum_default_jmp);
 
                        if (jumptable) {
+                               ZEND_ASSERT(opnum_switch != (uint32_t)-1);
                                opline = &CG(active_op_array)->opcodes[opnum_switch];
                                opline->extended_value = get_next_op_number();
                        }
@@ -4942,12 +4943,11 @@ void zend_compile_try(zend_ast *ast) /* {{{ */
                zend_bool is_last_catch = (i + 1 == catches->children);
 
                uint32_t *jmp_multicatch = safe_emalloc(sizeof(uint32_t), classes->children - 1, 0);
-               uint32_t opnum_catch;
+               uint32_t opnum_catch = (uint32_t)-1;
 
                CG(zend_lineno) = catch_ast->lineno;
 
                for (j = 0; j < classes->children; j++) {
-
                        zend_ast *class_ast = classes->child[j];
                        zend_bool is_last_class = (j + 1 == classes->children);
 
@@ -4997,6 +4997,7 @@ void zend_compile_try(zend_ast *ast) /* {{{ */
                        jmp_opnums[i + 1] = zend_emit_jump(0);
                }
 
+               ZEND_ASSERT(opnum_catch != (uint32_t)-1 && "Should have at least one class");
                opline = &CG(active_op_array)->opcodes[opnum_catch];
                if (!is_last_catch) {
                        opline->op2.opline_num = get_next_op_number();
index ca57b7eb156c9ec2ecc6c7dddf39ae78b4db0ad8..ee65b4107be20cc78881538f4da4e81c658db85b 100644 (file)
@@ -3076,7 +3076,7 @@ PHP_FUNCTION(mb_strimwidth)
 {
        char *str, *trimmarker = NULL;
        zend_string *encoding = NULL;
-       zend_long from, width, swidth;
+       zend_long from, width, swidth = 0;
        size_t str_len, trimmarker_len;
        mbfl_string string, result, marker, *ret;
 
index 96687e44f49fd6a46b26c4e42e6c9902fb95fd7b..1c7cbc7e55e1084b381a60a67d3335818f6c1fb6 100644 (file)
@@ -158,7 +158,7 @@ void scdf_solve(scdf_ctx *scdf, const char *name) {
                                /* Zero length blocks don't have a last instruction that would normally do this */
                                scdf_mark_edge_feasible(scdf, i, block->successors[0]);
                        } else {
-                               zend_op *opline;
+                               zend_op *opline = NULL;
                                int j, end = block->start + block->len;
                                for (j = block->start; j < end; j++) {
                                        opline = &scdf->op_array->opcodes[j];
@@ -170,6 +170,7 @@ void scdf_solve(scdf_ctx *scdf, const char *name) {
                                if (block->successors_count == 1) {
                                        scdf_mark_edge_feasible(scdf, i, block->successors[0]);
                                } else if (block->successors_count > 1) {
+                                       ZEND_ASSERT(opline && "Should have opline in non-empty block");
                                        if (opline->opcode == ZEND_OP_DATA) {
                                                opline--;
                                                j--;
index 9fe7793771ac14716115e78274d6b2d46d0f2218..337ac1e96de09337388571fe5ee28efe560f97f0 100644 (file)
@@ -533,7 +533,7 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags,
        int i, j;
        zend_op *opline, *end;
        int *tmp = NULL;
-       ALLOCA_FLAG(use_heap);
+       ALLOCA_FLAG(use_heap = 0);
 
        // FIXME: Can we optimize this copying out in some cases?
        if (blocks[n].next_child >= 0) {
index 6e0f22cd6e683e4883d7f51335fdd0e90057c2fa..98d9d2dd6883732dfb4c7b7ea514c1ebc2a6590e 100644 (file)
@@ -1370,7 +1370,7 @@ static PHP_METHOD(PDOStatement, fetchAll)
 {
        zend_long how = PDO_FETCH_USE_DEFAULT;
        zval data, *return_all;
-       zval *arg2;
+       zval *arg2 = NULL;
        zend_class_entry *old_ce;
        zval old_ctor_args, *ctor_args = NULL;
        int error = 0, flags, old_arg_count;
index 205d97255091d595fb59246081fbd6cf4be08c78..4f7d4969729634b9266d9e51d65ea2c5418278e8 100644 (file)
@@ -865,6 +865,11 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in
        zval retval;
        int ret;
 
+       // Exception occurred on previous callback. Don't attempt to call function.
+       if (EG(exception)) {
+               return 0;
+       }
+
        collation->fci.fci.size = (sizeof(collation->fci.fci));
        ZVAL_COPY_VALUE(&collation->fci.fci.function_name, &collation->cmp_func);
        collation->fci.fci.object = NULL;
@@ -876,13 +881,8 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in
 
        collation->fci.fci.params = zargs;
 
-       if (!EG(exception)) {
-               //Exception occurred on previous callback. Don't attempt to call function
-               if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
-                       php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
-               }
-       } else {
-               ZVAL_UNDEF(&retval);
+       if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
+               php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
        }
 
        zval_ptr_dtor(&zargs[0]);
index 32de9d2fe6a7e28f3e34f9ee6d7e9304c158d76a..37461b0d1df480219a3604395a20c81d925d04b7 100644 (file)
@@ -1488,7 +1488,7 @@ PHP_FUNCTION(stream_socket_enable_crypto)
        zend_long cryptokind = 0;
        zval *zstream, *zsessstream = NULL;
        php_stream *stream, *sessstream = NULL;
-       zend_bool enable, cryptokindnull;
+       zend_bool enable, cryptokindnull = 1;
        int ret;
 
        ZEND_PARSE_PARAMETERS_START(2, 4)
@@ -1502,7 +1502,7 @@ PHP_FUNCTION(stream_socket_enable_crypto)
        php_stream_from_zval(stream, zstream);
 
        if (enable) {
-               if (ZEND_NUM_ARGS() < 3 || cryptokindnull) {
+               if (cryptokindnull) {
                        zval *val;
 
                        if (!GET_CTX_OPT(stream, "ssl", "crypto_method", val)) {
index c78ec5ffacd760730afb9e9b1f054550d5ed77da..41a391876c76509e291d49b5235e8ef16c6d3d93 100644 (file)
@@ -5029,7 +5029,6 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
        uint8_t state = 0;
        size_t pos;
        char *allow_free = NULL;
-       const char *allow_actual;
        char is_xml = 0;
 
        buf = estrndup(rbuf, len);
@@ -5040,7 +5039,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
        br = 0;
        if (allow) {
                allow_free = zend_str_tolower_dup_ex(allow, allow_len);
-               allow_actual = allow_free ? allow_free : allow;
+               allow = allow_free ? allow_free : allow;
                tbuf = emalloc(PHP_TAG_BUF_SIZE + 1);
                tp = tbuf;
        } else {
@@ -5145,7 +5144,7 @@ state_1:
                                }
                                *(tp++) = '>';
                                *tp='\0';
-                               if (php_tag_find(tbuf, tp-tbuf, allow_actual)) {
+                               if (php_tag_find(tbuf, tp-tbuf, allow)) {
                                        memcpy(rp, tbuf, tp-tbuf);
                                        rp += tp-tbuf;
                                }
@@ -5339,11 +5338,11 @@ finish:
                *rp = '\0';
        }
        efree((void *)buf);
-       if (allow) {
+       if (tbuf) {
                efree(tbuf);
-               if (allow_free) {
-                       efree(allow_free);
-               }
+       }
+       if (allow_free) {
+               efree(allow_free);
        }
        if (stateptr)
                *stateptr = state;