-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault on /* */
comments
#64
Comments
Hi! In general, when you post a reproduction example like this, it is a lot more useful if you don't rely on unknown third party libraries like This is a pretty severe issue, so I spent some time this morning adapting your code so that it is actually reproducible. Here is the change that I made: 4,6d3
< #include <rz_types.h>
< #include <rz_list.h>
< #include <rz_util/rz_file.h>
25a23
>
32,36c30,36
< size_t read_bytes = 0;
< char *source_code = rz_file_slurp(file_path, &read_bytes);
< if (!source_code || !read_bytes) {
< return -1;
< }
---
> FILE *f = fopen(file_path, "rb");
> fseek(f, 0, SEEK_END);
> size_t read_bytes = ftell(f);
> fseek(f, 0, SEEK_SET);
> char *source_code = malloc(read_bytes);
> fread(source_code, 1, read_bytes, f);
> fclose(f); I'm just using standard C APIs instead of custom, third-party ones. With these changes, there is no segfault. Everything works as expected: clang -I ../tree-sitter/lib/include test.c src/parser.c ../tree-sitter/libtree-sitter.a
./a.out ts-crash.h Output:
|
Oh, sorry about that. Thank you for your investigation. I will check tomorrow again and will close tomorrow if it's indeed isn't reproducible with these changes 👍 |
Hmm, I removed the third-party library (rz-util) but crash is still here. To reproduce just run: meson build
ninja -C build
build/ts-c-cpp-parser test/ts-crash.h This project uses Tree-Sitter runtime and C grammar as statically-linked Meson subprojects (see Full log:
|
Nevermind, it's my lack of attention - it was in this line printf("node: %s\n", ts_node_type(struct_node)); which didn't exist in the AST obviously. Sorry for the trouble, indeed not a bug but my fault. |
The parser itself is:
The content of
ts-crash.h
is:The text was updated successfully, but these errors were encountered: