diff options
author | Yuan Fu <casouri@gmail.com> | 2024-06-01 10:33:18 -0700 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2024-06-01 10:33:18 -0700 |
commit | 00360258caddc0d8cf29ba3d9971125a06f8959b (patch) | |
tree | 4254f49a7ca16a508f449dad36506ffc95fb131d | |
parent | 20af58d3a13ddb5c2ca376da8cdd3fde4833ca2d (diff) | |
download | emacs-00360258caddc0d8cf29ba3d9971125a06f8959b.tar.gz emacs-00360258caddc0d8cf29ba3d9971125a06f8959b.tar.bz2 emacs-00360258caddc0d8cf29ba3d9971125a06f8959b.zip |
Fix treesit-parse-string crash (bug#71012)
Parsing a large file with treesit-parse-string and then printing the
returned node crashes Emacs, because with-temp-buffer kills the temp
buffer when treesit-parse-string returns, and print.c tries to access
the node's position in the killed buffer.
* lisp/treesit.el (treesit-parse-string): Don't use with-temp-buffer.
-rw-r--r-- | lisp/treesit.el | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 2676ed932dc..151d9302786 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -122,10 +122,13 @@ of max unsigned 32-bit value for byte offsets into buffer text." (defun treesit-parse-string (string language) "Parse STRING using a parser for LANGUAGE. Return the root node of the syntax tree." - (with-temp-buffer - (insert string) - (treesit-parser-root-node - (treesit-parser-create language)))) + ;; We can't use `with-temp-buffer' because it kills the buffer when + ;; returning from the form. + (let ((buf (generate-new-buffer " *treesit-parse-string*"))) + (with-current-buffer buf + (insert string) + (treesit-parser-root-node + (treesit-parser-create language))))) (defvar-local treesit-language-at-point-function nil "A function that returns the language at point. |