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
This commit is contained in:
Gabriel Ford authored and GitHub committed 2025-06-28 23:12:42 +00:00
1 parent 10a03e83e3
commit 331de6afa6
1 file changed
+5 -1
+5 -1
View File
@@ -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);