summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-10 15:46:58 +0100
committerChristian Brabandt <cb@256bit.org>2024-03-10 15:46:58 +0100
commit26dd09ad5e86f4e2179be0181421bfab9a6b3b75 (patch)
treecb58485dbd7ff9741ecfe4f3687b6a27863ba442 /src/evalfunc.c
parent82e079df814f7372e9579450730062b205449efa (diff)
patch 9.1.0164: Internal error when passing invalid position to getregion()v9.1.0164
Problem: Internal error or crash when passing invalid position to getregion(). Solution: Give an error for invalid position (zeertzjq). closes: #14172 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2bb9ccec55..1b394f00a5 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -5495,6 +5495,7 @@ f_getregion(typval_T *argvars, typval_T *rettv)
pos_T p1, p2;
char_u *type;
buf_T *save_curbuf = curbuf;
+ buf_T *findbuf = curbuf;
char_u default_type[] = "v";
int save_virtual = -1;
int l;
@@ -5536,19 +5537,44 @@ f_getregion(typval_T *argvars, typval_T *rettv)
else if (type[0] == Ctrl_V && type[1] == NUL)
region_type = MBLOCK;
else
+ {
+ semsg(_(e_invalid_value_for_argument_str_str), "type", type);
return;
+ }
if (fnum1 != 0)
{
- buf_T *findbuf;
-
findbuf = buflist_findnr(fnum1);
// buffer not loaded
if (findbuf == NULL || findbuf->b_ml.ml_mfp == NULL)
+ {
+ emsg(_(e_buffer_is_not_loaded));
return;
- curbuf = findbuf;
+ }
+ }
+
+ if (p1.lnum < 1 || p1.lnum > findbuf->b_ml.ml_line_count)
+ {
+ semsg(_(e_invalid_line_number_nr), p1.lnum);
+ return;
+ }
+ if (p1.col < 1 || p1.col > ml_get_buf_len(findbuf, p1.lnum) + 1)
+ {
+ semsg(_(e_invalid_column_number_nr), p1.col);
+ return;
+ }
+ if (p2.lnum < 1 || p2.lnum > findbuf->b_ml.ml_line_count)
+ {
+ semsg(_(e_invalid_line_number_nr), p2.lnum);
+ return;
+ }
+ if (p2.col < 1 || p2.col > ml_get_buf_len(findbuf, p2.lnum) + 1)
+ {
+ semsg(_(e_invalid_column_number_nr), p2.col);
+ return;
}
+ curbuf = findbuf;
save_virtual = virtual_op;
virtual_op = virtual_active();
@@ -5582,7 +5608,7 @@ f_getregion(typval_T *argvars, typval_T *rettv)
else if (p2.lnum > 1)
{
p2.lnum--;
- p2.col = (colnr_T)STRLEN(ml_get(p2.lnum));
+ p2.col = ml_get_len(p2.lnum);
if (p2.col > 0)
{
p2.col--;