Skip to content

Commit

Permalink
Issue #341 - No token can be inserted if istacksize == 0!
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffmcl committed Feb 8, 2016
1 parent 58229b7 commit 03a643f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/istack.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "attrs.h"
#include "streamio.h"
#include "tmbstr.h"
#if !defined(NDEBUG) && defined(_MSC_VER)
#include "sprtf.h"
#endif

/* duplicate attributes */
AttVal *TY_(DupAttrs)( TidyDocImpl* doc, AttVal *attrs)
Expand Down Expand Up @@ -115,6 +118,7 @@ static void PopIStack( TidyDocImpl* doc )
TY_(FreeAttribute)( doc, av );
}
TidyDocFree(doc, istack->element);
istack->element = NULL; /* remove the freed element */
}

static void PopIStackUntil( TidyDocImpl* doc, TidyTagId tid )
Expand Down Expand Up @@ -267,9 +271,12 @@ Node *TY_(InsertedToken)( TidyDocImpl* doc )
node->end = lexer->txtend; /* was : lexer->txtstart; */
istack = lexer->insert;

#if 0 && defined(_DEBUG)
/* #if 0 && defined(_DEBUG) */
#if !defined(NDEBUG) && defined(_MSC_VER)
if ( lexer->istacksize == 0 )
fprintf( stderr, "0-size istack!\n" );
{
SPRTF( "WARNING: ZERO sized istack!\n" );
}
#endif

node->element = TY_(tmbstrdup)(doc->allocator, istack->element);
Expand Down
9 changes: 6 additions & 3 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void Show_Node( TidyDocImpl* doc, const char *msg, Node *node )
tmbstr src = lex ? "lexer" : "stream";
SPRTF("R=%d C=%d: ", line, col );
// DEBUG: Be able to set a TRAP on a SPECIFIC row,col
if ((line == 8) && (col == 36)) {
if ((line == 67) && (col == 95)) {
check_me("Show_Node"); // just a debug trap
}
if (lexer && lexer->token &&
Expand Down Expand Up @@ -2264,8 +2264,11 @@ Node* TY_(GetToken)( TidyDocImpl* doc, GetTokenMode mode )
assert( !(lexer->pushed || lexer->itoken) );

/* at start of block elements, unclosed inline
elements are inserted into the token stream */
if (lexer->insert || lexer->inode) {
elements are inserted into the token stream
Issue #341 - Can NOT insert a token if NO istacksize
*/
if ((lexer->insert || lexer->inode) && lexer->istacksize)
{
/*\ Issue #92: could fix by the following, but instead chose not to stack these 2
* if ( !(lexer->insert && (nodeIsINS(lexer->insert) || nodeIsDEL(lexer->insert))) ) {
\*/
Expand Down

0 comments on commit 03a643f

Please sign in to comment.