aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/buffer.c
diff options
context:
space:
mode:
authornotomo <notomo.motono@gmail.com>2023-07-04 23:07:55 +0900
committerGitHub <noreply@github.com>2023-07-04 22:07:55 +0800
commit3ecd45ded044c47efa76b74e9e3b720fbe27adc7 (patch)
treeb77a31ec1aac5f7c9fc4ed1555347abca228a095 /src/nvim/api/buffer.c
parentcf5f1492d702f940934b0b40024d1741e4474542 (diff)
downloadrneovim-3ecd45ded044c47efa76b74e9e3b720fbe27adc7.tar.gz
rneovim-3ecd45ded044c47efa76b74e9e3b720fbe27adc7.tar.bz2
rneovim-3ecd45ded044c47efa76b74e9e3b720fbe27adc7.zip
fix(api): allow negative column arguments for nvim_buf_set_text (#23501)
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r--src/nvim/api/buffer.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 5bf7295bb3..8774aee20b 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -547,6 +547,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
// Another call to ml_get_buf() may free the line, so make a copy.
str_at_start = xstrdup(ml_get_buf(buf, (linenr_T)start_row, false));
size_t len_at_start = strlen(str_at_start);
+ start_col = start_col < 0 ? (int64_t)len_at_start + start_col + 1 : start_col;
VALIDATE_RANGE((start_col >= 0 && (size_t)start_col <= len_at_start), "start_col", {
goto early_end;
});
@@ -554,6 +555,7 @@ void nvim_buf_set_text(uint64_t channel_id, Buffer buffer, Integer start_row, In
// Another call to ml_get_buf() may free the line, so make a copy.
str_at_end = xstrdup(ml_get_buf(buf, (linenr_T)end_row, false));
size_t len_at_end = strlen(str_at_end);
+ end_col = end_col < 0 ? (int64_t)len_at_end + end_col + 1 : end_col;
VALIDATE_RANGE((end_col >= 0 && (size_t)end_col <= len_at_end), "end_col", {
goto early_end;
});