]> 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:45 +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 83bd649bb981d57c642c9b220cdcc11321f4ef24..04a867a48a3b16cab88dccdf1624690323cb591f 100644 (file)
@@ -4732,7 +4732,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;
 
@@ -4825,6 +4825,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();
                        }
@@ -4917,12 +4918,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);
 
@@ -4972,6 +4972,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 11107e1108fb1fd29c931389d708fdbe1d0ff896..06ea201608fc568b8d37f78b474f980633d955de 100644 (file)
@@ -2971,7 +2971,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 f1f71f0b15ad1bdfc779415c2ede6e66df37b437..d4b024aa04495e08cf87e4779b66ba3d8f57577c 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 0825cc6771490a324209e029b25f94dc120100ea..f5881c1e6c4366f385eec71f4adc66925917c243 100644 (file)
@@ -1371,7 +1371,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 683932216dadd869b14c2c09ae98432d251e55b8..2668a6e51bfa6ef0fe1827edafa23279cf0eff9e 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 56b9f43da5a3347e42cef32182339c04ed7966b7..a4a87b3273b4f3cf98c72f8ede38bc70b4799656 100644 (file)
@@ -4848,7 +4848,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);
@@ -4859,7 +4858,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 {
@@ -4964,7 +4963,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;
                                }
@@ -5158,11 +5157,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;