neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 2b766e1f4d51f0bd435005a7ee9e2e25245a7987
parent b95848a8f11d5e8096555efcf69d2c5b4536c997
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon, 22 Dec 2025 14:14:21 +0800

Merge pull request #37068 from janlazo/vim-9.0.0154

vim-patch:9.0.{154,1899}
Diffstat:
Msrc/nvim/ops.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/nvim/ops.c b/src/nvim/ops.c @@ -1046,11 +1046,20 @@ static void mb_adjust_opend(oparg_T *oap) } } -/// Put character 'c' at position 'lp' -static inline void pbyte(pos_T lp, int c) +/// put byte 'c' at position 'lp', but +/// verify, that the position to place +/// is actually safe +static void pbyte(pos_T lp, int c) { assert(c <= UCHAR_MAX); - *(ml_get_buf_mut(curbuf, lp.lnum) + lp.col) = (char)c; + char *p = ml_get_buf_mut(curbuf, lp.lnum); + colnr_T len = curbuf->b_ml.ml_line_len; + + // safety check + if (lp.col >= len) { + lp.col = (len > 1 ? len - 2 : 0); + } + *(p + lp.col) = (char)c; if (!curbuf_splice_pending) { extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo); } @@ -1865,7 +1874,7 @@ char *skip_comment(char *line, bool process, bool include_space, bool *is_commen return line; } -/// @param count number of lines (minimal 2) to join at cursor position. +/// @param count number of lines (minimal 2) to join at the cursor position. /// @param save_undo when true, save lines for undo first. /// @param use_formatoptions set to false when e.g. processing backspace and comment /// leaders should not be removed.