Skip to content

Commit f1fc6bb

Browse files
committed
Suggested changes from Tim
Remove leading _, change the trace string building to append the comma within the loop
1 parent 9e866be commit f1fc6bb

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

Zend/zend_exceptions.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ ZEND_METHOD(ErrorException, getSeverity)
506506
} \
507507
} while (0)
508508

509-
static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
509+
static void build_trace_args(zval *arg, smart_str *str) /* {{{ */
510510
{
511511
/* the trivial way would be to do
512512
* convert_to_string(arg);
@@ -516,24 +516,21 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
516516

517517
ZVAL_DEREF(arg);
518518

519-
if (smart_str_append_zval(str, arg, EG(exception_string_param_max_len)) == SUCCESS) {
520-
smart_str_appends(str, ", ");
521-
} else {
519+
if (smart_str_append_zval(str, arg, EG(exception_string_param_max_len)) != SUCCESS) {
522520
switch (Z_TYPE_P(arg)) {
523521
case IS_RESOURCE:
524522
smart_str_appends(str, "Resource id #");
525523
smart_str_append_long(str, Z_RES_HANDLE_P(arg));
526-
smart_str_appends(str, ", ");
527524
break;
528525
case IS_ARRAY:
529-
smart_str_appends(str, "Array, ");
526+
smart_str_appends(str, "Array");
530527
break;
531528
case IS_OBJECT: {
532529
zend_string *class_name = Z_OBJ_HANDLER_P(arg, get_class_name)(Z_OBJ_P(arg));
533530
smart_str_appends(str, "Object(");
534531
/* cut off on NULL byte ... class@anonymous */
535532
smart_str_appends(str, ZSTR_VAL(class_name));
536-
smart_str_appends(str, "), ");
533+
smart_str_appends(str, ")");
537534
zend_string_release_ex(class_name, 0);
538535
break;
539536
}
@@ -542,32 +539,32 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
542539
}
543540
/* }}} */
544541

545-
static void _build_trace_args_list(zval *tmp, smart_str *str) /* {{{ */
542+
static void build_trace_args_list(zval *tmp, smart_str *str) /* {{{ */
546543
{
547544
if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) {
548-
size_t last_len = ZSTR_LEN(str->s);
549545
zend_string *name;
550546
zval *arg;
547+
HashTable *ht = Z_ARRVAL_P(tmp);
548+
uint32_t index = 0;
551549

552-
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) {
550+
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) {
553551
if (name) {
554552
smart_str_append(str, name);
555553
smart_str_appends(str, ": ");
556554
}
557-
_build_trace_args(arg, str);
555+
build_trace_args(arg, str);
556+
if (++index != zend_hash_num_elements(ht)) {
557+
smart_str_appends(str, ", ");
558+
}
558559
} ZEND_HASH_FOREACH_END();
559-
560-
if (last_len != ZSTR_LEN(str->s)) {
561-
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */
562-
}
563560
} else {
564561
/* only happens w/ reflection abuse (Zend/tests/bug63762.phpt) */
565562
zend_error(E_WARNING, "args element is not an array");
566563
}
567564
}
568565
/* }}} */
569566

570-
static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t num) /* {{{ */
567+
static void build_trace_string(smart_str *str, const HashTable *ht, uint32_t num) /* {{{ */
571568
{
572569
zval *file, *tmp;
573570

@@ -613,7 +610,7 @@ static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t nu
613610
smart_str_appendc(str, '(');
614611
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS));
615612
if (tmp) {
616-
_build_trace_args_list(tmp, str);
613+
build_trace_args_list(tmp, str);
617614
}
618615
smart_str_appends(str, ")\n");
619616
}
@@ -622,11 +619,10 @@ static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t nu
622619
/* {{{ Gets the function arguments printed as a string from a backtrace frame. */
623620
ZEND_API zend_string *zend_trace_function_args_to_string(const HashTable *frame) {
624621
smart_str str = {0};
625-
smart_str_appends(&str, "");
626622

627623
zval *tmp = zend_hash_find_known_hash(frame, ZSTR_KNOWN(ZEND_STR_ARGS));
628624
if (tmp) {
629-
_build_trace_args_list(tmp, &str);
625+
build_trace_args_list(tmp, &str);
630626
}
631627

632628
return smart_str_extract(&str);
@@ -640,12 +636,11 @@ ZEND_API zend_string *zend_trace_current_function_args_string(void) {
640636
zval backtrace;
641637
zend_fetch_debug_backtrace(&backtrace, /* skip_last */ 0, /* options */ 0, /* limit */ 1);
642638
/* can fail esp if low memory condition */
643-
if (Z_TYPE(backtrace) != IS_ARRAY) {
644-
return NULL;
645-
}
646-
zval *first_frame = zend_hash_index_find(Z_ARRVAL(backtrace), 0);
647-
if (first_frame) {
648-
dynamic_params = zend_trace_function_args_to_string(Z_ARRVAL_P(first_frame));
639+
if (Z_TYPE(backtrace) == IS_ARRAY) {
640+
zval *first_frame = zend_hash_index_find(Z_ARRVAL(backtrace), 0);
641+
if (first_frame) {
642+
dynamic_params = zend_trace_function_args_to_string(Z_ARRVAL_P(first_frame));
643+
}
649644
}
650645
zval_ptr_dtor(&backtrace);
651646
return dynamic_params;
@@ -664,7 +659,7 @@ ZEND_API zend_string *zend_trace_to_string(const HashTable *trace, bool include_
664659
continue;
665660
}
666661

667-
_build_trace_string(&str, Z_ARRVAL_P(frame), num++);
662+
build_trace_string(&str, Z_ARRVAL_P(frame), num++);
668663
} ZEND_HASH_FOREACH_END();
669664

670665
if (include_main) {

0 commit comments

Comments
 (0)