mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user