Skip to content

Commit c09b635

Browse files
committed
Fix potentially uninitialized warnings in phpdbg
1 parent 88bfd2a commit c09b635

File tree

8 files changed

+47
-41
lines changed

8 files changed

+47
-41
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,11 @@ static PHP_FUNCTION(phpdbg_end_oplog)
671671

672672
{
673673
zend_string *last_file = NULL;
674-
HashTable *file_ht;
674+
HashTable *file_ht = NULL;
675675
zend_string *last_function = (void *)~(uintptr_t)0;
676676
zend_class_entry *last_scope = NULL;
677677

678-
HashTable *insert_ht;
678+
HashTable *insert_ht = NULL;
679679
zend_long insert_idx;
680680

681681
do {
@@ -717,6 +717,7 @@ static PHP_FUNCTION(phpdbg_end_oplog)
717717
insert_idx = cur->op->lineno;
718718
}
719719

720+
ZEND_ASSERT(insert_ht && file_ht);
720721
{
721722
zval *num = zend_hash_index_find(insert_ht, insert_idx);
722723
if (!num) {

sapi/phpdbg/phpdbg_frame.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void phpdbg_switch_frame(int frame) /* {{{ */
171171

172172
static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
173173
{
174-
zval *funcname, *class, class_zv, *type, *args, *argstmp;
174+
zval *funcname, *class, class_zv, *args, *argstmp;
175175

176176
funcname = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("function"));
177177

@@ -183,21 +183,22 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
183183
}
184184

185185
if (class) {
186-
type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
186+
zval *type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
187+
188+
phpdbg_xml(" symbol=\"%s%s%s\"", Z_STRVAL_P(class), Z_STRVAL_P(type), Z_STRVAL_P(funcname));
189+
phpdbg_out("%s%s%s(", Z_STRVAL_P(class), Z_STRVAL_P(type), Z_STRVAL_P(funcname));
190+
} else {
191+
phpdbg_xml(" symbol=\"%s\"", Z_STRVAL_P(funcname));
192+
phpdbg_out("%s(", Z_STRVAL_P(funcname));
187193
}
188194

189195
args = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("args"));
190-
191-
phpdbg_xml(" symbol=\"%s%s%s\"", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
192-
193196
if (args) {
194197
phpdbg_xml(">");
195198
} else {
196199
phpdbg_xml(" />");
197200
}
198201

199-
phpdbg_out("%s%s%s(", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
200-
201202
if (args) {
202203
const zend_function *func = NULL;
203204
const zend_arg_info *arginfo = NULL;

sapi/phpdbg/phpdbg_info.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,20 @@ PHPDBG_INFO(literal) /* {{{ */
343343
PHPDBG_INFO(memory) /* {{{ */
344344
{
345345
size_t used, real, peak_used, peak_real;
346-
zend_mm_heap *heap;
346+
zend_mm_heap *orig_heap = NULL;
347347
zend_bool is_mm;
348348

349349
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
350-
heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
350+
orig_heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
351351
}
352352
if ((is_mm = is_zend_mm())) {
353353
used = zend_memory_usage(0);
354354
real = zend_memory_usage(1);
355355
peak_used = zend_memory_peak_usage(0);
356356
peak_real = zend_memory_peak_usage(1);
357357
}
358-
if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
359-
zend_mm_set_heap(heap);
358+
if (orig_heap) {
359+
zend_mm_set_heap(orig_heap);
360360
}
361361

362362
if (is_mm) {

sapi/phpdbg/phpdbg_out.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,9 +1030,8 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m
10301030
} else {
10311031
phpdbg_mixed_write(fd, msg, msglen);
10321032
}
1033-
return msglen;
10341033
}
1035-
break;
1034+
return msglen;
10361035

10371036
/* no formatting on logging output */
10381037
case P_LOG:
@@ -1046,6 +1045,7 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m
10461045
}
10471046
}
10481047
break;
1048+
EMPTY_SWITCH_DEFAULT_CASE()
10491049
}
10501050

10511051
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,33 +1687,33 @@ int phpdbg_interactive(zend_bool allow_async_unsafe, char *input) /* {{{ */
16871687
return ret;
16881688
} /* }}} */
16891689

1690+
static inline void list_code() {
1691+
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
1692+
const char *file_char = zend_get_executed_filename();
1693+
zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
1694+
phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno());
1695+
efree(file);
1696+
}
1697+
}
1698+
16901699
/* code may behave weirdly if EG(exception) is set; thus backup it */
16911700
#define DO_INTERACTIVE(allow_async_unsafe) do { \
1692-
const zend_op *backup_opline; \
1693-
const zend_op *before_ex; \
16941701
if (exception) { \
1702+
const zend_op *before_ex = EG(opline_before_exception); \
1703+
const zend_op *backup_opline = NULL; \
16951704
if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { \
16961705
backup_opline = EG(current_execute_data)->opline; \
16971706
} \
1698-
before_ex = EG(opline_before_exception); \
16991707
GC_ADDREF(exception); \
17001708
zend_clear_exception(); \
1701-
} \
1702-
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \
1703-
const char *file_char = zend_get_executed_filename(); \
1704-
zend_string *file = zend_string_init(file_char, strlen(file_char), 0); \
1705-
phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno()); \
1706-
efree(file); \
1707-
} \
1708-
\
1709-
switch (phpdbg_interactive(allow_async_unsafe, NULL)) { \
1710-
zval zv; \
1711-
case PHPDBG_LEAVE: \
1712-
case PHPDBG_FINISH: \
1713-
case PHPDBG_UNTIL: \
1714-
case PHPDBG_NEXT: \
1715-
if (exception) { \
1716-
if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) \
1709+
list_code(); \
1710+
switch (phpdbg_interactive(allow_async_unsafe, NULL)) { \
1711+
zval zv; \
1712+
case PHPDBG_LEAVE: \
1713+
case PHPDBG_FINISH: \
1714+
case PHPDBG_UNTIL: \
1715+
case PHPDBG_NEXT: \
1716+
if (backup_opline \
17171717
&& (backup_opline->opcode == ZEND_HANDLE_EXCEPTION || backup_opline->opcode == ZEND_CATCH)) { \
17181718
EG(current_execute_data)->opline = backup_opline; \
17191719
EG(exception) = exception; \
@@ -1722,11 +1722,12 @@ int phpdbg_interactive(zend_bool allow_async_unsafe, char *input) /* {{{ */
17221722
zend_throw_exception_internal(&zv); \
17231723
} \
17241724
EG(opline_before_exception) = before_ex; \
1725-
} \
1726-
/* fallthrough */ \
1727-
default: \
1728-
goto next; \
1725+
} \
1726+
} else { \
1727+
list_code(); \
1728+
phpdbg_interactive(allow_async_unsafe, NULL); \
17291729
} \
1730+
goto next; \
17301731
} while (0)
17311732

17321733
void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */

sapi/phpdbg/phpdbg_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent,
430430
PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg) {
431431
int ret = FAILURE;
432432
zend_bool new_index = 1;
433-
char *last_index;
433+
char *last_index = NULL;
434434
size_t index_len = 0;
435435
zval *zv;
436436

sapi/phpdbg/phpdbg_wait.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
243243
zend_extension *extension;
244244
zend_llist_position pos;
245245
zval *name = NULL;
246-
zend_string *strkey;
246+
zend_string *strkey = NULL;
247247

248248
extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos);
249249
while (extension) {
@@ -257,6 +257,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
257257
break;
258258
}
259259
name = NULL;
260+
strkey = NULL;
260261
} ZEND_HASH_FOREACH_END();
261262

262263
if (name) {
@@ -283,6 +284,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
283284
pefree(elm, zend_extensions.persistent);
284285
zend_extensions.count--;
285286
} else {
287+
ZEND_ASSERT(strkey);
286288
zend_hash_del(Z_ARRVAL_P(zvp), strkey);
287289
}
288290
}

sapi/phpdbg/phpdbg_watch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,13 +1014,14 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) {
10141014
}
10151015
if (watch->type == WATCH_ON_BUCKET) {
10161016
if (watch->backup.bucket.key != watch->addr.bucket->key || (watch->backup.bucket.key != NULL && watch->backup.bucket.h != watch->addr.bucket->h)) {
1017-
phpdbg_watch_element *element;
1017+
phpdbg_watch_element *element = NULL;
10181018
zval *new;
10191019

10201020
ZEND_HASH_FOREACH_PTR(&watch->elements, element) {
10211021
break;
10221022
} ZEND_HASH_FOREACH_END();
10231023

1024+
ZEND_ASSERT(element); /* elements must be non-empty */
10241025
new = zend_symtable_find(element->parent_container, element->name_in_parent);
10251026

10261027
if (!new) {

0 commit comments

Comments
 (0)