TUI: always use safe cursor movement after resize

The old code could lead to a memory error in the following situation:

0. The previous cursor position was row 50 since before, on a grid
larger than 50 rows.
1. grid_resize changes the grid height to 40, and invalidly assumes the
resize moved the physical cursor to row 0
2. Some event used a operation that could move the cursor (such as clear), and
then reset the cursor to the "true" position row 50 (pointless after #8221, but
I forgot to remove it)
3. raw_line/cheap_to_print is invoked, and tries to inspect the grid at
row 50 (memory error)
4. grid_cursor_goto would have been called at this point, and set a
valid cursor position 0-39.
This commit is contained in:
Björn Linse
2018-10-02 13:46:53 +02:00
parent 39ad99b594
commit cc305213d7
2 changed files with 11 additions and 9 deletions

View File

@@ -32,7 +32,6 @@ void ugrid_resize(UGrid *grid, int width, int height)
grid->cells[i] = xcalloc((size_t)width, sizeof(UCell));
}
grid->row = grid->col = 0;
grid->width = width;
grid->height = height;
}