From a0375b68c1803e7453071a20b28249020abe7260 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Jun 2023 04:31:17 +0800 Subject: vim-patch:9.0.1598: screenchar() and others are wrong with DBCS 'encoding' (#23872) Problem: screenchar(), screenchars() and screenstring() do not work properly when 'encoding' is set to a double-byte encoding. Solution: Fix the way the bytes of the characters are obtained. (issue vim/vim#12469) https://github.com/vim/vim/commit/47eec6716b8621fd43bac8ecc9c19089df26705e --- src/nvim/grid.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 76dd2a073a..aa542c5a2f 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -138,8 +138,9 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr) grid_puts(grid, buf, row, col, attr); } -/// get a single character directly from grid.chars into "bytes[]". -/// Also return its attribute in *attrp; +/// Get a single character directly from grid.chars into "bytes", which must +/// have a size of "MB_MAXBYTES + 1". +/// If "attrp" is not NULL, return the character's attribute in "*attrp". void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) { grid_adjust(&grid, &row, &col); @@ -150,7 +151,9 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp) } size_t off = grid->line_offset[row] + (size_t)col; - *attrp = grid->attrs[off]; + if (attrp != NULL) { + *attrp = grid->attrs[off]; + } schar_copy(bytes, grid->chars[off]); } -- cgit