mirror of
https://github.com/tmux/tmux.git
synced 2026-03-06 15:55:33 +00:00
grid_peek_cell can return NULL, so check for it. From Conor Taylor in
GitHub issue 4848.
This commit is contained in:
6
grid.c
6
grid.c
@@ -1089,12 +1089,16 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
off = 0;
|
off = 0;
|
||||||
|
|
||||||
gl = grid_peek_line(gd, py);
|
gl = grid_peek_line(gd, py);
|
||||||
|
if (gl == NULL) {
|
||||||
|
buf[0] = '\0';
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
if (flags & GRID_STRING_EMPTY_CELLS)
|
if (flags & GRID_STRING_EMPTY_CELLS)
|
||||||
end = gl->cellsize;
|
end = gl->cellsize;
|
||||||
else
|
else
|
||||||
end = gl->cellused;
|
end = gl->cellused;
|
||||||
for (xx = px; xx < px + nx; xx++) {
|
for (xx = px; xx < px + nx; xx++) {
|
||||||
if (gl == NULL || xx >= end)
|
if (xx >= end)
|
||||||
break;
|
break;
|
||||||
grid_get_cell(gd, xx, py, &gc);
|
grid_get_cell(gd, xx, py, &gc);
|
||||||
if (gc.flags & GRID_FLAG_PADDING)
|
if (gc.flags & GRID_FLAG_PADDING)
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ window_copy_clone_screen(struct screen *src, struct screen *hint, u_int *cx,
|
|||||||
if (trim) {
|
if (trim) {
|
||||||
while (sy > screen_hsize(src)) {
|
while (sy > screen_hsize(src)) {
|
||||||
gl = grid_peek_line(src->grid, sy - 1);
|
gl = grid_peek_line(src->grid, sy - 1);
|
||||||
if (gl->cellused != 0)
|
if (gl == NULL || gl->cellused != 0)
|
||||||
break;
|
break;
|
||||||
sy--;
|
sy--;
|
||||||
}
|
}
|
||||||
@@ -3625,6 +3625,10 @@ window_copy_stringify(struct grid *gd, u_int py, u_int first, u_int last,
|
|||||||
buf = xrealloc(buf, bufsize);
|
buf = xrealloc(buf, bufsize);
|
||||||
|
|
||||||
gl = grid_peek_line(gd, py);
|
gl = grid_peek_line(gd, py);
|
||||||
|
if (gl == NULL) {
|
||||||
|
buf[*size - 1] = '\0';
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
bx = *size - 1;
|
bx = *size - 1;
|
||||||
for (ax = first; ax < last; ax++) {
|
for (ax = first; ax < last; ax++) {
|
||||||
d = window_copy_cellstring(gl, ax, &dlen, &allocated);
|
d = window_copy_cellstring(gl, ax, &dlen, &allocated);
|
||||||
@@ -3670,6 +3674,10 @@ window_copy_cstrtocellpos(struct grid *gd, u_int ncells, u_int *ppx, u_int *ppy,
|
|||||||
px = *ppx;
|
px = *ppx;
|
||||||
pywrap = *ppy;
|
pywrap = *ppy;
|
||||||
gl = grid_peek_line(gd, pywrap);
|
gl = grid_peek_line(gd, pywrap);
|
||||||
|
if (gl == NULL) {
|
||||||
|
free(cells);
|
||||||
|
return;
|
||||||
|
}
|
||||||
while (cell < ncells) {
|
while (cell < ncells) {
|
||||||
cells[cell].d = window_copy_cellstring(gl, px,
|
cells[cell].d = window_copy_cellstring(gl, px,
|
||||||
&cells[cell].dlen, &cells[cell].allocated);
|
&cells[cell].dlen, &cells[cell].allocated);
|
||||||
@@ -3679,6 +3687,8 @@ window_copy_cstrtocellpos(struct grid *gd, u_int ncells, u_int *ppx, u_int *ppy,
|
|||||||
px = 0;
|
px = 0;
|
||||||
pywrap++;
|
pywrap++;
|
||||||
gl = grid_peek_line(gd, pywrap);
|
gl = grid_peek_line(gd, pywrap);
|
||||||
|
if (gl == NULL)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4080,7 +4090,7 @@ window_copy_visible_lines(struct window_copy_mode_data *data, u_int *start,
|
|||||||
|
|
||||||
for (*start = gd->hsize - data->oy; *start > 0; (*start)--) {
|
for (*start = gd->hsize - data->oy; *start > 0; (*start)--) {
|
||||||
gl = grid_peek_line(gd, (*start) - 1);
|
gl = grid_peek_line(gd, (*start) - 1);
|
||||||
if (~gl->flags & GRID_LINE_WRAPPED)
|
if (gl == NULL || ~gl->flags & GRID_LINE_WRAPPED)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*end = gd->hsize - data->oy + gd->sy;
|
*end = gd->hsize - data->oy + gd->sy;
|
||||||
|
|||||||
Reference in New Issue
Block a user