diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-22 06:41:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-22 06:41:51 +0800 |
commit | 8af3d641daf03610c824ca4e0dffa07db297cb5b (patch) | |
tree | 8e79e3c6aacf683e5c15eab3ee48f0d4d71feea8 | |
parent | 946c8fd2886df9db288797c257bf067b904a3551 (diff) | |
download | rneovim-8af3d641daf03610c824ca4e0dffa07db297cb5b.tar.gz rneovim-8af3d641daf03610c824ca4e0dffa07db297cb5b.tar.bz2 rneovim-8af3d641daf03610c824ca4e0dffa07db297cb5b.zip |
fix(grid): don't use utfc_ptr2char_len() when printing until NUL (#19456)
-rw-r--r-- | src/nvim/grid.c | 21 | ||||
-rw-r--r-- | test/functional/ui/statusline_spec.lua | 9 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 1268f987e1..72e85c425d 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -230,16 +230,12 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col && *ptr != NUL) { c = *ptr; // check if this is the first byte of a multibyte - if (len > 0) { - mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); - } else { - mbyte_blen = utfc_ptr2len((char *)ptr); - } - if (len >= 0) { - u8c = utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)); - } else { - u8c = utfc_ptr2char(ptr, u8cc); - } + mbyte_blen = len > 0 + ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) + : utfc_ptr2len((char *)ptr); + u8c = len >= 0 + ? 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)) { // Do Arabic shaping. @@ -248,8 +244,9 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col nc = NUL; nc1 = NUL; } else { - nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, - (int)((text + len) - ptr - mbyte_blen)); + nc = len >= 0 + ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, (int)((text + len) - ptr - mbyte_blen)) + : utfc_ptr2char(ptr + mbyte_blen, pcc); nc1 = pcc[0]; } pc = prev_c; diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua index 2ffd3149a6..760760150c 100644 --- a/test/functional/ui/statusline_spec.lua +++ b/test/functional/ui/statusline_spec.lua @@ -1,5 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') +local assert_alive = helpers.assert_alive local clear = helpers.clear local command = helpers.command local feed = helpers.feed @@ -368,3 +369,11 @@ describe('global statusline', function() eq(1, meths.get_option('cmdheight')) end) end) + +it('statusline does not crash if it has Arabic characters #19447', function() + clear() + meths.set_option('statusline', 'غً') + meths.set_option('laststatus', 2) + command('redraw!') + assert_alive() +end) |