Repository navigation
Conversation
ParseTreePatternMatcher::split stored TextChunk and TagChunk objects by value in a std::vector<Chunk>, slicing them to the base class, so tokenize() could never recognise a tag and read a TextChunk's text out of bounds from the sliced object. compile() then built the pattern tree with a ParserInterpreter and CommonTokenStream that were locals, so the returned ParseTreePattern pointed at a freed tree and freed tokens, the text-chunk tokens pointed at a stack ANTLRInputStream, match(tree, string, ruleIndex) returned a ParseTreeMatch referencing a local pattern, and Lexer::reset() dereferenced the null input left behind by tokenize(), which crashed on the second text chunk of a pattern. Keep chunks in unique_ptrs, copy token text while the temporary stream is alive, let compile() parse with a ParserInterpreter that owns its token source and stream and hand it to the ParseTreePattern so the tree and tokens live as long as the pattern, store the pattern by value in ParseTreeMatch, and guard the null input in Lexer::reset() as the Java runtime does. Signed-off-by: obsidian_nomad <abdul@sproutxp.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The C++ port of the tree pattern matcher cannot be used: every call into it is undefined behaviour.
The pattern now owns the parser that created its tree, and through it the tokens; chunks are held through unique_ptr; token text is copied while the temporary stream is alive. split() therefore returns std::vector<std::unique_ptr>, which no working caller can depend on today since the old signature could only return sliced objects.
New gtest compiles and matches patterns against an interpreted grammar: it crashes on dev and passes under ASan with this change. The C++ runtime testsuite (362 tests) passes.