From 099ed2bd56e7f379f4d5e9e9a83ddfb3cdc99d5e Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 3 Jul 2025 23:36:44 -0700 Subject: [PATCH] Handle the case when ts_node_type returns NULL (bug#78938) * src/treesit.c (Ftreesit_node_type): Handle NULL. (cherry picked from commit 30dae2ad23963bc902101544cbbe2c5698beddd7) --- src/treesit.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index 7b8e5d161f7..8b066b09ef7 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -485,6 +485,7 @@ static Lisp_Object Vtreesit_str_space; static Lisp_Object Vtreesit_str_equal; static Lisp_Object Vtreesit_str_match; static Lisp_Object Vtreesit_str_pred; +static Lisp_Object Vtreesit_str_empty; /* This is the limit on recursion levels for some tree-sitter functions. Remember to update docstrings when changing this value. @@ -2853,8 +2854,9 @@ If NODE is nil, return nil. */) treesit_initialize (); TSNode treesit_node = XTS_NODE (node)->node; + /* ts_node_type could return NULL, see source code. */ const char *type = ts_node_type (treesit_node); - return build_string (type); + return type == NULL ? Vtreesit_str_empty : build_string (type); } DEFUN ("treesit-node-start", @@ -5299,7 +5301,9 @@ buffer. */); staticpro (&Vtreesit_str_match); Vtreesit_str_match = build_string ("match"); staticpro (&Vtreesit_str_pred); - Vtreesit_str_pred = build_string ("pred"); + Vtreesit_str_pred = build_pure_c_string ("pred"); + staticpro (&Vtreesit_str_empty); + Vtreesit_str_empty = build_pure_c_string (""); defsubr (&Streesit_language_available_p); defsubr (&Streesit_library_abi_version); -- 2.39.5