mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +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) | void tui_screenshot(TUIData *tui, String path) | ||||||
| { | { | ||||||
|  |   FILE *f = fopen(path.data, "w"); | ||||||
|  |   if (f == NULL) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   UGrid *grid = &tui->grid; |   UGrid *grid = &tui->grid; | ||||||
|   flush_buf(tui); |   flush_buf(tui); | ||||||
|   grid->row = 0; |   grid->row = 0; | ||||||
|   grid->col = 0; |   grid->col = 0; | ||||||
|  |  | ||||||
|   FILE *f = fopen(path.data, "w"); |  | ||||||
|   tui->screenshot = f; |   tui->screenshot = f; | ||||||
|   fprintf(f, "%d,%d\n", grid->height, grid->width); |   fprintf(f, "%d,%d\n", grid->height, grid->width); | ||||||
|   unibi_out(tui, unibi_clear_screen); |   unibi_out(tui, unibi_clear_screen); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Gabriel Ford
					Gabriel Ford