@@ -2048,24 +2048,52 @@ void dbg_show_node( TidyDocImpl* doc, Node *node, int caller, int indent )
20482048 SPRTF ("\n" );
20492049}
20502050
2051- /* Tail recursion here with sensible compilers will re-use
2052- the stack frame and avoid overflows during debugging.
2051+ /* Make this non-recursive, because we really do want to eliminate
2052+ recursion that makes us crash, even when debugging.
20532053 */
2054- void dbg_show_all_nodes_loop ( TidyDocImpl * doc , Node * node , int indent )
2054+ void dbg_show_all_nodes ( TidyDocImpl * doc , Node * node , int indent )
20552055{
2056- while ( node && (node = node -> next ) )
2056+ Stack * stack = TY_ (newStack )(doc , 16 );
2057+ Node * child = NULL ;
2058+ Node * next = NULL ;
2059+
2060+ dbg_show_node ( doc , node , 0 , indent ++ );
2061+
2062+ if ( (child = node -> content ) )
20572063 {
2058- dbg_show_node ( doc , node , 0 , indent );
2059- dbg_show_all_nodes_loop ( doc , node -> content , indent + 1 );
2060- }
2061- }
2064+ while ( child )
2065+ {
2066+ if ( (next = child -> next ) )
2067+ {
2068+ next -> idx = indent ;
2069+ }
2070+
2071+ dbg_show_node ( doc , child , 0 , indent );
2072+
2073+ if (child -> content )
2074+ {
2075+ TY_ (push )(stack , next );
2076+ indent ++ ;
2077+ child = child -> content ;
2078+ continue ;
2079+ }
20622080
2063- void dbg_show_all_nodes ( TidyDocImpl * doc , Node * node , int indent )
2064- {
2065- dbg_show_node ( doc , node , 0 , indent );
2066- dbg_show_all_nodes_loop ( doc , node -> content , indent + 1 );
2067- }
2081+ if (next )
2082+ {
2083+ child = next ;
2084+ }
2085+ else
2086+ {
2087+ if ( (child = TY_ (pop )(stack )) )
2088+ {
2089+ indent = child -> idx ;
2090+ }
2091+ }
20682092
2093+ }
2094+ TY_ (freeStack )(stack );
2095+ }
2096+ }
20692097#endif
20702098
20712099int tidyDocCleanAndRepair ( TidyDocImpl * doc )
0 commit comments