@@ -685,24 +685,36 @@ ZEND_METHOD(Exception, __toString)
685
685
}
686
686
687
687
if ((Z_OBJCE_P (exception ) == zend_ce_type_error || Z_OBJCE_P (exception ) == zend_ce_argument_count_error ) && strstr (ZSTR_VAL (message ), ", called in " )) {
688
- zend_string * real_message = zend_strpprintf (0 , "%s and defined" , ZSTR_VAL (message ));
688
+ zval message_zv ;
689
+ ZVAL_STR (& message_zv , message );
690
+ zend_string * real_message = zend_strpprintf_unchecked (0 , "%Z and defined" , & message_zv );
689
691
zend_string_release_ex (message , 0 );
690
692
message = real_message ;
691
693
}
692
694
695
+ zend_string * tmp_trace = (Z_TYPE (trace ) == IS_STRING && Z_STRLEN (trace ))
696
+ ? zend_string_copy (Z_STR (trace ))
697
+ : ZSTR_INIT_LITERAL ("#0 {main}\n" , false);
698
+
699
+ zval name_zv , trace_zv , file_zv , prev_str_zv ;
700
+ ZVAL_STR (& name_zv , Z_OBJCE_P (exception )-> name );
701
+ ZVAL_STR (& trace_zv , tmp_trace );
702
+ ZVAL_STR (& file_zv , file );
703
+ ZVAL_STR (& prev_str_zv , prev_str );
704
+
693
705
if (ZSTR_LEN (message ) > 0 ) {
694
- str = zend_strpprintf (0 , "%s: %s in %s:" ZEND_LONG_FMT
695
- "\nStack trace:\n%s%s%s" ,
696
- ZSTR_VAL (Z_OBJCE_P (exception )-> name ), ZSTR_VAL (message ), ZSTR_VAL (file ), line ,
697
- (Z_TYPE (trace ) == IS_STRING && Z_STRLEN (trace )) ? Z_STRVAL (trace ) : "#0 {main}\n" ,
698
- ZSTR_LEN (prev_str ) ? "\n\nNext " : "" , ZSTR_VAL (prev_str ));
706
+ zval message_zv ;
707
+ ZVAL_STR (& message_zv , message );
708
+
709
+ str = zend_strpprintf_unchecked (0 , "%Z: %Z in %Z:" ZEND_LONG_FMT "\nStack trace:\n%Z%s%Z" ,
710
+ & name_zv , & message_zv , & file_zv , line ,
711
+ & trace_zv , ZSTR_LEN (prev_str ) ? "\n\nNext " : "" , & prev_str_zv );
699
712
} else {
700
- str = zend_strpprintf (0 , "%s in %s:" ZEND_LONG_FMT
701
- "\nStack trace:\n%s%s%s" ,
702
- ZSTR_VAL (Z_OBJCE_P (exception )-> name ), ZSTR_VAL (file ), line ,
703
- (Z_TYPE (trace ) == IS_STRING && Z_STRLEN (trace )) ? Z_STRVAL (trace ) : "#0 {main}\n" ,
704
- ZSTR_LEN (prev_str ) ? "\n\nNext " : "" , ZSTR_VAL (prev_str ));
713
+ str = zend_strpprintf_unchecked (0 , "%Z in %Z:" ZEND_LONG_FMT "\nStack trace:\n%Z%s%Z" ,
714
+ & name_zv , & file_zv , line ,
715
+ & trace_zv , ZSTR_LEN (prev_str ) ? "\n\nNext " : "" , & prev_str_zv );
705
716
}
717
+ zend_string_release_ex (tmp_trace , false);
706
718
707
719
zend_string_release_ex (prev_str , 0 );
708
720
zend_string_release_ex (message , 0 );
0 commit comments