@@ -41,7 +41,7 @@ void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC)
41
41
if (exception == add_previous || !add_previous || !exception ) {
42
42
return ;
43
43
}
44
- if (Z_TYPE_P (add_previous ) != IS_OBJECT && !instanceof_function (Z_OBJCE_P (add_previous ), default_exception_ce TSRMLS_CC )) {
44
+ if (Z_TYPE_P (add_previous ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (add_previous ), default_exception_ce TSRMLS_CC )) {
45
45
zend_error (E_ERROR , "Cannot set non exception as previous exception" );
46
46
return ;
47
47
}
@@ -586,7 +586,7 @@ ZEND_METHOD(exception, getTraceAsString)
586
586
int res_len = 0 , * len = & res_len , num = 0 ;
587
587
588
588
DEFAULT_0_PARAMS ;
589
-
589
+
590
590
trace = zend_read_property (default_exception_ce , getThis (), "trace" , sizeof ("trace" )- 1 , 1 TSRMLS_CC );
591
591
if (Z_TYPE_P (trace ) != IS_ARRAY ) {
592
592
RETURN_FALSE ;
@@ -602,8 +602,8 @@ ZEND_METHOD(exception, getTraceAsString)
602
602
TRACE_APPEND_STRL (s_tmp , strlen (s_tmp ));
603
603
efree (s_tmp );
604
604
605
- res [res_len ] = '\0' ;
606
- RETURN_STRINGL (res , res_len , 0 );
605
+ res [res_len ] = '\0' ;
606
+ RETURN_STRINGL (res , res_len , 0 );
607
607
}
608
608
/* }}} */
609
609
@@ -640,15 +640,15 @@ ZEND_METHOD(exception, __toString)
640
640
int len = 0 ;
641
641
zend_fcall_info fci ;
642
642
zval fname ;
643
-
643
+
644
644
DEFAULT_0_PARAMS ;
645
-
645
+
646
646
str = estrndup ("" , 0 );
647
647
648
648
exception = getThis ();
649
649
ZVAL_STRINGL (& fname , "gettraceasstring" , sizeof ("gettraceasstring" )- 1 , 1 );
650
650
651
- while (exception && Z_TYPE_P (exception ) == IS_OBJECT ) {
651
+ while (exception && Z_TYPE_P (exception ) == IS_OBJECT && instanceof_function ( Z_OBJCE_P ( exception ), default_exception_ce TSRMLS_CC ) ) {
652
652
prev_str = str ;
653
653
_default_exception_get_entry (exception , "message" , sizeof ("message" )- 1 , & message TSRMLS_CC );
654
654
_default_exception_get_entry (exception , "file" , sizeof ("file" )- 1 , & file TSRMLS_CC );
@@ -658,6 +658,7 @@ ZEND_METHOD(exception, __toString)
658
658
convert_to_string (& file );
659
659
convert_to_long (& line );
660
660
661
+ trace = NULL ;
661
662
fci .size = sizeof (fci );
662
663
fci .function_table = & Z_OBJCE_P (exception )-> function_table ;
663
664
fci .function_name = & fname ;
@@ -670,7 +671,7 @@ ZEND_METHOD(exception, __toString)
670
671
671
672
zend_call_function (& fci , NULL TSRMLS_CC );
672
673
673
- if (Z_TYPE_P (trace ) != IS_STRING ) {
674
+ if (trace && Z_TYPE_P (trace ) != IS_STRING ) {
674
675
zval_ptr_dtor (& trace );
675
676
trace = NULL ;
676
677
}
0 commit comments