diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
commit | 9837de570c5972f98e74848edc97c297a13136ea (patch) | |
tree | cc948611912d116a3f98a744e690d3d7b6e2f59a /src/nvim/grid.c | |
parent | c367400b73d207833d51e09d663f969ffab37531 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.gz rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.bz2 rneovim-9837de570c5972f98e74848edc97c297a13136ea.zip |
Merge remote-tracking branch 'upstream/master' into colorcolchar
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]; |