aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/grid.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-11-24 05:59:06 +0800
committerGitHub <noreply@github.com>2023-11-24 05:59:06 +0800
commit4ed1c2a8afc71f1e3e2bc6835dc95f284782fe52 (patch)
tree79ea8415d6ba3312dec9d1ba7473b3580ff8b7a2 /src/nvim/grid.c
parent4ce3159e24e18ccd53400f7066a54e01561cf586 (diff)
downloadrneovim-4ed1c2a8afc71f1e3e2bc6835dc95f284782fe52.tar.gz
rneovim-4ed1c2a8afc71f1e3e2bc6835dc95f284782fe52.tar.bz2
rneovim-4ed1c2a8afc71f1e3e2bc6835dc95f284782fe52.zip
fix(grid): don't draw beyond max column (#26172)
Diffstat (limited to 'src/nvim/grid.c')
-rw-r--r--src/nvim/grid.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/nvim/grid.c b/src/nvim/grid.c
index a9d2bf92f7..e25dcfe4bf 100644
--- a/src/nvim/grid.c
+++ b/src/nvim/grid.c
@@ -348,6 +348,9 @@ schar_T grid_line_getchar(int col, int *attr)
void grid_line_put_schar(int col, schar_T schar, int attr)
{
assert(grid_line_grid);
+ if (col >= grid_line_maxcol) {
+ return;
+ }
linebuf_char[col] = schar;
linebuf_attr[col] = attr;
@@ -374,7 +377,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr)
int start_col = col;
- int max_col = grid_line_maxcol;
+ const int max_col = grid_line_maxcol;
while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) {
// check if this is the first byte of a multibyte
int mbyte_blen = len > 0
@@ -428,16 +431,20 @@ int grid_line_puts(int col, const char *text, int textlen, int attr)
void grid_line_fill(int start_col, int end_col, int c, int attr)
{
+ end_col = MIN(end_col, grid_line_maxcol);
+ if (start_col >= end_col) {
+ return;
+ }
+
schar_T sc = schar_from_char(c);
for (int col = start_col; col < end_col; col++) {
linebuf_char[col] = sc;
linebuf_attr[col] = attr;
linebuf_vcol[col] = -1;
}
- if (start_col < end_col) {
- grid_line_first = MIN(grid_line_first, start_col);
- grid_line_last = MAX(grid_line_last, end_col);
- }
+
+ grid_line_first = MIN(grid_line_first, start_col);
+ grid_line_last = MAX(grid_line_last, end_col);
}
/// move the cursor to a position in a currently rendered line.
@@ -496,7 +503,8 @@ void grid_line_flush(void)
{
ScreenGrid *grid = grid_line_grid;
grid_line_grid = NULL;
- if (!(grid_line_first < grid_line_last)) {
+ assert(grid_line_last <= grid_line_maxcol);
+ if (grid_line_first >= grid_line_last) {
return;
}