euclidianAce / ltreesitter

Standalone tree sitter bindings for the Lua language
MIT License
85 stars 4 forks source link

Don't raise a segmentation fault when calling named_child #19

Closed pbaam closed 1 year ago

pbaam commented 1 year ago

This script will segfault:

#!/usr/bin/env lua

ltreesitter = require"ltreesitter"
json = ltreesitter.require"json"
tree = json:parse_string('{"a": 1, "b": 2, "c": 3}')

print(tree:root():child(0):named_child(3))

The number of named children is 3, but the number of children is 7. So using indexes between 3 and 7 will result in a segmentation fault. Using indexes above 7 will print nil as expected The grammar used is https://github.com/tree-sitter/tree-sitter-json/tree/73076754005a460947cafe8e03a8cf5fa4fa2938

euclidianAce commented 1 year ago

Thanks!