summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sapi/phpdbg/phpdbg_frame.c6
-rw-r--r--sapi/phpdbg/phpdbg_opcode.c40
-rw-r--r--sapi/phpdbg/phpdbg_print.c14
-rw-r--r--sapi/phpdbg/phpdbg_utils.c30
4 files changed, 48 insertions, 42 deletions
diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c
index 189b3b20fa..4f0e5e88b0 100644
--- a/sapi/phpdbg/phpdbg_frame.c
+++ b/sapi/phpdbg/phpdbg_frame.c
@@ -164,7 +164,11 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
}
++j;
- php_printf("%s", phpdbg_short_zval_print(argstmp, 40));
+ {
+ char *arg_print = phpdbg_short_zval_print(argstmp, 40);
+ php_printf("%s", arg_print);
+ efree(arg_print);
+ }
phpdbg_xml("</arg>");
} ZEND_HASH_FOREACH_END();
diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c
index b64fa5c491..8a58a44f0b 100644
--- a/sapi/phpdbg/phpdbg_opcode.c
+++ b/sapi/phpdbg/phpdbg_opcode.c
@@ -34,12 +34,14 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t
switch (type) {
case IS_CV: {
zend_string *var = ops->vars[EX_VAR_TO_NUM(op->var)];
- asprintf(&decode, "$%.*s%c", ZSTR_LEN(var) <= 19 ? (int) ZSTR_LEN(var) : 18, ZSTR_VAL(var), ZSTR_LEN(var) <= 19 ? 0 : '+');
+ spprintf(&decode, 0, "$%.*s%c",
+ ZSTR_LEN(var) <= 19 ? (int) ZSTR_LEN(var) : 18,
+ ZSTR_VAL(var), ZSTR_LEN(var) <= 19 ? 0 : '+');
} break;
case IS_VAR:
case IS_TMP_VAR: {
- asprintf(&decode, "@%" PRIu32, EX_VAR_TO_NUM(op->var) - ops->last_var);
+ spprintf(&decode, 0, "@%td", EX_VAR_TO_NUM(op->var) - ops->last_var);
} break;
case IS_CONST: {
zval *literal = RT_CONSTANT(ops, *op);
@@ -58,13 +60,13 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
switch (op->opcode) {
case ZEND_FAST_CALL:
if (op->extended_value != 0) {
- asprintf(&decode[0], "FAST_CALL<%s>",
+ spprintf(&decode[0], 0, "FAST_CALL<%s>",
op->extended_value == ZEND_FAST_CALL_FROM_CATCH ? "FROM_CATCH" : "FROM_FINALLY");
}
break;
case ZEND_FAST_RET:
if (op->extended_value != 0) {
- asprintf(&decode[0], "FAST_RET<%s>",
+ spprintf(&decode[0], 0, "FAST_RET<%s>",
op->extended_value == ZEND_FAST_RET_TO_CATCH ? "TO_CATCH" : "TO_FINALLY");
}
break;
@@ -74,14 +76,14 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
switch (op->opcode) {
case ZEND_JMP:
case ZEND_FAST_CALL:
- asprintf(&decode[1], "J%ld", OP_JMP_ADDR(op, op->op1) - ops->opcodes);
+ spprintf(&decode[1], 0, "J%td", OP_JMP_ADDR(op, op->op1) - ops->opcodes);
break;
case ZEND_INIT_FCALL:
case ZEND_RECV:
case ZEND_RECV_INIT:
case ZEND_RECV_VARIADIC:
- asprintf(&decode[1], "%" PRIu32, op->op1.num);
+ spprintf(&decode[1], 0, "%" PRIu32, op->op1.num);
break;
default:
@@ -92,7 +94,9 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
/* OP2 */
switch (op->opcode) {
case ZEND_JMPZNZ:
- asprintf(&decode[2], "J%ld or J%ld", OP_JMP_ADDR(op, op->op2) - ops->opcodes, ZEND_OFFSET_TO_OPLINE(op, op->extended_value) - ops->opcodes);
+ spprintf(&decode[2], 0, "J%td or J%td",
+ OP_JMP_ADDR(op, op->op2) - ops->opcodes,
+ ZEND_OFFSET_TO_OPLINE(op, op->extended_value) - ops->opcodes);
break;
case ZEND_JMPZ:
@@ -101,13 +105,13 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
case ZEND_JMPNZ_EX:
case ZEND_JMP_SET:
case ZEND_ASSERT_CHECK:
- asprintf(&decode[2], "J%ld", OP_JMP_ADDR(op, op->op2) - ops->opcodes);
+ spprintf(&decode[2], 0, "J%td", OP_JMP_ADDR(op, op->op2) - ops->opcodes);
break;
case ZEND_FAST_CALL:
case ZEND_FAST_RET:
if (op->extended_value != 0) {
- asprintf(&decode[2], "J%" PRIu32, op->op2.opline_num);
+ spprintf(&decode[2], 0, "J%" PRIu32, op->op2.opline_num);
}
break;
@@ -118,7 +122,7 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
case ZEND_SEND_REF:
case ZEND_SEND_VAR_EX:
case ZEND_SEND_USER:
- asprintf(&decode[2], "%" PRIu32, op->op2.num);
+ spprintf(&decode[2], 0, "%" PRIu32, op->op2.num);
break;
default:
@@ -129,14 +133,14 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
/* RESULT */
switch (op->opcode) {
case ZEND_CATCH:
- asprintf(&decode[2], "%" PRIu32, op->result.num);
+ spprintf(&decode[2], 0, "%" PRIu32, op->result.num);
break;
default:
decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type);
break;
}
- asprintf(&result,
+ spprintf(&result, 0,
"%-23s %-20s %-20s %-20s",
decode[0] ? decode[0] : opcode_name,
decode[1] ? decode[1] : "",
@@ -144,13 +148,13 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
decode[3] ? decode[3] : "");
if (decode[0])
- free(decode[0]);
+ efree(decode[0]);
if (decode[1])
- free(decode[1]);
+ efree(decode[1]);
if (decode[2])
- free(decode[2]);
+ efree(decode[2]);
if (decode[3])
- free(decode[3]);
+ efree(decode[3]);
return result;
} /* }}} */
@@ -183,9 +187,7 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_fl
execute_data->func->op_array.filename ? ZSTR_VAL(execute_data->func->op_array.filename) : "unknown");
}
- if (decode) {
- free(decode);
- }
+ efree(decode);
}
if (PHPDBG_G(oplog_list)) {
diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c
index b7bb9e688a..4a00189b46 100644
--- a/sapi/phpdbg/phpdbg_print.c
+++ b/sapi/phpdbg/phpdbg_print.c
@@ -82,15 +82,11 @@ static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */
do {
char *decode = phpdbg_decode_opline(op_array, opline);
- if (decode != NULL) {
- phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s",
- opline->lineno,
- opcode,
- decode);
- free(decode);
- } else {
- phpdbg_error("print", "type=\"decodefailure\" opline=\"%16p\"", "Failed to decode opline %16p", opline);
- }
+ phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s",
+ opline->lineno,
+ opcode,
+ decode);
+ efree(decode);
opline++;
} while (opcode++ < end);
}
diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c
index 112f340d6b..fc34c094b6 100644
--- a/sapi/phpdbg/phpdbg_utils.c
+++ b/sapi/phpdbg/phpdbg_utils.c
@@ -764,22 +764,22 @@ char *phpdbg_short_zval_print(zval *zv, int maxlen) /* {{{ */
switch (Z_TYPE_P(zv)) {
case IS_UNDEF:
- decode = zend_strndup("", 0);
+ decode = estrdup("");
break;
case IS_NULL:
- decode = zend_strndup(ZEND_STRL("null"));
+ decode = estrdup("null");
break;
case IS_FALSE:
- decode = zend_strndup(ZEND_STRL("false"));
+ decode = estrdup("false");
break;
case IS_TRUE:
- decode = zend_strndup(ZEND_STRL("true"));
+ decode = estrdup("true");
break;
case IS_LONG:
- asprintf(&decode, ZEND_ULONG_FMT, Z_LVAL_P(zv));
+ spprintf(&decode, 0, ZEND_LONG_FMT, Z_LVAL_P(zv));
break;
case IS_DOUBLE:
- asprintf(&decode, "%.*G", 14, Z_DVAL_P(zv));
+ spprintf(&decode, 0, "%.*G", 14, Z_DVAL_P(zv));
break;
case IS_STRING: {
int i;
@@ -789,28 +789,32 @@ char *phpdbg_short_zval_print(zval *zv, int maxlen) /* {{{ */
ZSTR_VAL(str)[i] = ' ';
}
}
- asprintf(&decode, "\"%.*s\"%c", ZSTR_LEN(str) <= maxlen - 2 ? (int) ZSTR_LEN(str) : (maxlen - 3), ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen - 2 ? 0 : '+');
+ spprintf(&decode, 0, "\"%.*s\"%c",
+ ZSTR_LEN(str) <= maxlen - 2 ? (int) ZSTR_LEN(str) : (maxlen - 3),
+ ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen - 2 ? 0 : '+');
zend_string_release(str);
} break;
case IS_RESOURCE:
- asprintf(&decode, "Rsrc #%d", Z_RES_HANDLE_P(zv));
+ spprintf(&decode, 0, "Rsrc #%d", Z_RES_HANDLE_P(zv));
break;
case IS_ARRAY:
- asprintf(&decode, "array(%d)", zend_hash_num_elements(Z_ARR_P(zv)));
+ spprintf(&decode, 0, "array(%d)", zend_hash_num_elements(Z_ARR_P(zv)));
break;
case IS_OBJECT: {
zend_string *str = Z_OBJCE_P(zv)->name;
- asprintf(&decode, "%.*s%c", ZSTR_LEN(str) <= maxlen ? (int) ZSTR_LEN(str) : maxlen - 1, ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen ? 0 : '+');
+ spprintf(&decode, 0, "%.*s%c",
+ ZSTR_LEN(str) <= maxlen ? (int) ZSTR_LEN(str) : maxlen - 1,
+ ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen ? 0 : '+');
break;
}
case IS_CONSTANT:
- decode = zend_strndup(ZEND_STRL("<constant>"));
+ decode = estrdup("<constant>");
break;
case IS_CONSTANT_AST:
- decode = zend_strndup(ZEND_STRL("<ast>"));
+ decode = estrdup("<ast>");
break;
default:
- asprintf(&decode, "unknown type: %d", Z_TYPE_P(zv));
+ spprintf(&decode, 0, "unknown type: %d", Z_TYPE_P(zv));
break;
}