patch 9.1.0164: Internal error when passing invalid position to getregion()

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>
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 2bb9cce..1b394f0 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -5495,6 +5495,7 @@
     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 @@
     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 @@
 	    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--;