diff -r f9391e2b74a5 -r 157fcc4fcb70 Parser/tokenizer.c --- a/Parser/tokenizer.c Fri Feb 19 08:57:50 2016 +0100 +++ b/Parser/tokenizer.c Sun Feb 21 13:57:30 2016 -0800 @@ -1022,7 +1022,10 @@ else { tok->done = E_OK; tok->inp = strchr(tok->buf, '\0'); - done = tok->inp[-1] == '\n'; + + if (tok->inp != tok->buf) { + done = tok->inp[-1] == '\n'; + } } } else { @@ -1525,6 +1528,22 @@ memcpy(&ahead_tok, tok, sizeof(ahead_tok)); ahead_tok_kind = tok_get(&ahead_tok, &ahead_tok_start, &ahead_tok_end); + + /* tok_get has the ability to free ahead_tok.buf. This is + a problem for tok since they now share the same pointer, + due the memcpy above. Therefore, if ahead_tok.buf is null, + we also need to null out tok->buf. */ + if (ahead_tok.buf == NULL) { + tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL; + /* ahead_tok failed for some reason - copy the reason. */ + tok->done = ahead_tok.done; + } + + if (ahead_tok_kind == ERRORTOKEN) { + /* if our lookahead token is an error, we need to + bail now. */ + return ERRORTOKEN; + } if (ahead_tok_kind == NAME && ahead_tok.cur - ahead_tok.start == 3