Skip to content

Commit b024012

Browse files
committed
share code path for arg list string building
1 parent 96c4363 commit b024012

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
@@ -526,6 +526,31 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
526526
}
527527
/* }}} */
528528

529+
static void _build_trace_args_list(zval *tmp, smart_str *str) /* {{{ */
530+
{
531+
if (Z_TYPE_P(tmp) == IS_ARRAY) {
532+
size_t last_len = ZSTR_LEN(str->s);
533+
zend_string *name;
534+
zval *arg;
535+
536+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
537+
if (name) {
538+
smart_str_append(str, name);
539+
smart_str_appends(str, ": ");
540+
}
541+
_build_trace_args(arg, str);
542+
} ZEND_HASH_FOREACH_END();
543+
544+
if (last_len != ZSTR_LEN(str->s)) {
545+
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
546+
}
547+
} else {
548+
/* only happens w/ reflection abuse (Zend/tests/bug63762.phpt) */
549+
zend_error(E_WARNING, "args element is not an array");
550+
}
551+
}
552+
/* }}} */
553+
529554
static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* {{{ */
530555
{
531556
zval *file, *tmp;
@@ -563,25 +588,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /*
563588
smart_str_appendc(str, '(');
564589
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS));
565590
if (tmp) {
566-
if (Z_TYPE_P(tmp) == IS_ARRAY) {
567-
size_t last_len = ZSTR_LEN(str->s);
568-
zend_string *name;
569-
zval *arg;
570-
571-
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
572-
if (name) {
573-
smart_str_append(str, name);
574-
smart_str_appends(str, ": ");
575-
}
576-
_build_trace_args(arg, str);
577-
} ZEND_HASH_FOREACH_END();
578-
579-
if (last_len != ZSTR_LEN(str->s)) {
580-
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
581-
}
582-
} else {
583-
zend_error(E_WARNING, "args element is not an array");
584-
}
591+
_build_trace_args_list(tmp, str);
585592
}
586593
smart_str_appends(str, ")\n");
587594
}
@@ -595,25 +602,7 @@ ZEND_API zend_string *zend_trace_function_args_to_string(HashTable *frame) {
595602

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

619608
smart_str_0(&str);

0 commit comments

Comments
 (0)