neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 331de6afa6ffa28ea5165de50adb39c5f61a52c2
parent 10a03e83e357f118be90a11d8b281d8459718b86
Author: Gabriel Ford <gabe@fordltc.net>
Date:   Sat, 28 Jun 2025 19:12:42 -0400

fix(tui): don't crash when nvim__screenshot() is called with bad path (#34594)

Problem: Currently `vim.api.nvim__screenshot()` crashes when called with an
invalid path. This is because we don't check if `fopen()` returns a null
pointer.

Solution: Bail out if `fopen()` returns a null pointer.

Fixes: https://github.com/neovim/neovim/issues/34593
Diffstat:
Msrc/nvim/tui/tui.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c @@ -1653,12 +1653,16 @@ void tui_set_icon(TUIData *tui, String icon) void tui_screenshot(TUIData *tui, String path) { + FILE *f = fopen(path.data, "w"); + if (f == NULL) { + return; + } + UGrid *grid = &tui->grid; flush_buf(tui); grid->row = 0; grid->col = 0; - FILE *f = fopen(path.data, "w"); tui->screenshot = f; fprintf(f, "%d,%d\n", grid->height, grid->width); unibi_out(tui, unibi_clear_screen);