diff options
Diffstat (limited to 'src/nvim/grid.c')
-rw-r--r-- | src/nvim/grid.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 2b73ff895d..46f8a59710 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -11,9 +11,19 @@ // // The grid_*() functions write to the screen and handle updating grid->lines[]. +#include <assert.h> +#include <limits.h> +#include <stdlib.h> + #include "nvim/arabic.h" +#include "nvim/buffer_defs.h" +#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" +#include "nvim/log.h" +#include "nvim/message.h" +#include "nvim/option_defs.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" @@ -130,18 +140,18 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) /// get a single character directly from grid.chars into "bytes[]". /// Also return its attribute in *attrp; -void grid_getbytes(ScreenGrid *grid, int row, int col, char_u *bytes, int *attrp) +void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) { - size_t off; - grid_adjust(&grid, &row, &col); // safety check - if (grid->chars != NULL && row < grid->rows && col < grid->cols) { - off = grid->line_offset[row] + (size_t)col; - *attrp = grid->attrs[off]; - schar_copy((char *)bytes, grid->chars[off]); + if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) { + return; } + + size_t off = grid->line_offset[row] + (size_t)col; + *attrp = grid->attrs[off]; + schar_copy(bytes, grid->chars[off]); } /// put string '*text' on the window grid at position 'row' and 'col', with @@ -243,7 +253,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) : utfc_ptr2len(ptr); u8c = len >= 0 - ? utfc_ptr2char_len((char_u *)ptr, u8cc, (int)((text + len) - ptr)) + ? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)) : utfc_ptr2char(ptr, u8cc); mbyte_cells = utf_char2cells(u8c); if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { @@ -254,7 +264,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col, nc1 = NUL; } else { nc = len >= 0 - ? utfc_ptr2char_len((char_u *)ptr + mbyte_blen, pcc, + ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, (int)((text + len) - ptr - mbyte_blen)) : utfc_ptr2char(ptr + mbyte_blen, pcc); nc1 = pcc[0]; |