summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
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--;