comparison src/textprop.c @ 26775:2df40c348c70 v8.2.3916

patch 8.2.3916: no error for passing an invalid line number to append() Commit: https://github.com/vim/vim/commit/8dac2acd6a79d571ff5409d9c90b4c9e73237eb4 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 27 20:57:06 2021 +0000 patch 8.2.3916: no error for passing an invalid line number to append() Problem: No error for passing an invalid line number to append(). Solution: In Vim9 script check for a non-negative number. (closes https://github.com/vim/vim/issues/9417)
author Bram Moolenaar <Bram@vim.org>
date Mon, 27 Dec 2021 22:00:04 +0100
parents 685206b54ecf
children bce848ec8b1b
comparison
equal deleted inserted replaced
26774:73cedd119ce2 26775:2df40c348c70
46 46
47 // The last used text property type ID. 47 // The last used text property type ID.
48 static int proptype_id = 0; 48 static int proptype_id = 0;
49 49
50 static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist"); 50 static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist");
51 static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld");
52 static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld");
53 51
54 /* 52 /*
55 * Find a property type by name, return the hashitem. 53 * Find a property type by name, return the hashitem.
56 * Returns NULL if the item can't be found. 54 * Returns NULL if the item can't be found.
57 */ 55 */
167 165
168 start_lnum = tv_get_number(&argvars[0]); 166 start_lnum = tv_get_number(&argvars[0]);
169 start_col = tv_get_number(&argvars[1]); 167 start_col = tv_get_number(&argvars[1]);
170 if (start_col < 1) 168 if (start_col < 1)
171 { 169 {
172 semsg(_(e_invalid_col), (long)start_col); 170 semsg(_(e_invalid_column_number_nr), (long)start_col);
173 return; 171 return;
174 } 172 }
175 if (argvars[2].v_type != VAR_DICT) 173 if (argvars[2].v_type != VAR_DICT)
176 { 174 {
177 emsg(_(e_dictreq)); 175 emsg(_(e_dictreq));
211 if (type == NULL) 209 if (type == NULL)
212 return FAIL; 210 return FAIL;
213 211
214 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) 212 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count)
215 { 213 {
216 semsg(_(e_invalid_lnum), (long)start_lnum); 214 semsg(_(e_invalid_line_number_nr), (long)start_lnum);
217 return FAIL; 215 return FAIL;
218 } 216 }
219 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) 217 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count)
220 { 218 {
221 semsg(_(e_invalid_lnum), (long)end_lnum); 219 semsg(_(e_invalid_line_number_nr), (long)end_lnum);
222 return FAIL; 220 return FAIL;
223 } 221 }
224 222
225 if (buf->b_ml.ml_mfp == NULL) 223 if (buf->b_ml.ml_mfp == NULL)
226 { 224 {
241 col = start_col; 239 col = start_col;
242 else 240 else
243 col = 1; 241 col = 1;
244 if (col - 1 > (colnr_T)textlen) 242 if (col - 1 > (colnr_T)textlen)
245 { 243 {
246 semsg(_(e_invalid_col), (long)start_col); 244 semsg(_(e_invalid_column_number_nr), (long)start_col);
247 return FAIL; 245 return FAIL;
248 } 246 }
249 247
250 if (lnum == end_lnum) 248 if (lnum == end_lnum)
251 length = end_col - col; 249 length = end_col - col;