Skip to content

Commit 5281590

Browse files
committed
share code path for arg list string building
1 parent a22fa38 commit 5281590

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

Zend/zend_exceptions.c

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,31 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
529529
}
530530
/* }}} */
531531

532+
static void _build_trace_args_list(zval *tmp, smart_str *str) /* {{{ */
533+
{
534+
if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) {
535+
size_t last_len = ZSTR_LEN(str->s);
536+
zend_string *name;
537+
zval *arg;
538+
539+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
540+
if (name) {
541+
smart_str_append(str, name);
542+
smart_str_appends(str, ": ");
543+
}
544+
_build_trace_args(arg, str);
545+
} ZEND_HASH_FOREACH_END();
546+
547+
if (last_len != ZSTR_LEN(str->s)) {
548+
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
549+
}
550+
} else {
551+
/* only happens w/ reflection abuse (Zend/tests/bug63762.phpt) */
552+
zend_error(E_WARNING, "args element is not an array");
553+
}
554+
}
555+
/* }}} */
556+
532557
static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t num) /* {{{ */
533558
{
534559
zval *file, *tmp;
@@ -566,25 +591,7 @@ static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t nu
566591
smart_str_appendc(str, '(');
567592
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS));
568593
if (tmp) {
569-
if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) {
570-
size_t last_len = ZSTR_LEN(str->s);
571-
zend_string *name;
572-
zval *arg;
573-
574-
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
575-
if (name) {
576-
smart_str_append(str, name);
577-
smart_str_appends(str, ": ");
578-
}
579-
_build_trace_args(arg, str);
580-
} ZEND_HASH_FOREACH_END();
581-
582-
if (last_len != ZSTR_LEN(str->s)) {
583-
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
584-
}
585-
} else {
586-
zend_error(E_WARNING, "args element is not an array");
587-
}
594+
_build_trace_args_list(tmp, str);
588595
}
589596
smart_str_appends(str, ")\n");
590597
}
@@ -598,25 +605,7 @@ ZEND_API zend_string *zend_trace_function_args_to_string(HashTable *frame) {
598605

599606
tmp = zend_hash_find_known_hash(frame, ZSTR_KNOWN(ZEND_STR_ARGS));
600607
if (tmp) {
601-
if (Z_TYPE_P(tmp) == IS_ARRAY) {
602-
size_t last_len = ZSTR_LEN(str.s);
603-
zend_string *name;
604-
zval *arg;
605-
606-
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
607-
if (name) {
608-
smart_str_append(&str, name);
609-
smart_str_appends(&str, ": ");
610-
}
611-
_build_trace_args(arg, &str);
612-
} ZEND_HASH_FOREACH_END();
613-
614-
if (last_len != ZSTR_LEN(str.s)) {
615-
ZSTR_LEN(str.s) -= 2; /* remove last ', ' */
616-
}
617-
} else {
618-
smart_str_appends(&str, "<<invalid argument array>>");
619-
}
608+
_build_trace_args_list(tmp, &str);
620609
}
621610

622611
smart_str_0(&str);

0 commit comments

Comments
 (0)