To: vim_dev@googlegroups.com Subject: Patch 8.2.3916 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3916 Problem: No error for passing an invalid line number to append(). Solution: In Vim9 script check for a non-negative number. (closes #9417) Files: src/evalbuffer.c, src/textprop.c, src/errors.h, src/indent.c, src/eval.c, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.3915/src/evalbuffer.c 2021-12-12 16:26:35.864627610 +0000 --- src/evalbuffer.c 2021-12-27 20:38:43.452867954 +0000 *************** *** 151,156 **** --- 151,158 ---- if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) { rettv->vval.v_number = 1; // FAIL + if (in_vim9script() && lnum < 1) + semsg(_(e_invalid_line_number_nr), lnum_arg); return; } *** ../vim-8.2.3915/src/textprop.c 2021-11-23 11:46:12.409848336 +0000 --- src/textprop.c 2021-12-27 19:55:31.203117594 +0000 *************** *** 48,55 **** static int proptype_id = 0; static char_u e_type_not_exist[] = N_("E971: Property type %s does not exist"); - static char_u e_invalid_col[] = N_("E964: Invalid column number: %ld"); - static char_u e_invalid_lnum[] = N_("E966: Invalid line number: %ld"); /* * Find a property type by name, return the hashitem. --- 48,53 ---- *************** *** 169,175 **** start_col = tv_get_number(&argvars[1]); if (start_col < 1) { ! semsg(_(e_invalid_col), (long)start_col); return; } if (argvars[2].v_type != VAR_DICT) --- 167,173 ---- start_col = tv_get_number(&argvars[1]); if (start_col < 1) { ! semsg(_(e_invalid_column_number_nr), (long)start_col); return; } if (argvars[2].v_type != VAR_DICT) *************** *** 213,224 **** if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) { ! semsg(_(e_invalid_lnum), (long)start_lnum); return FAIL; } if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) { ! semsg(_(e_invalid_lnum), (long)end_lnum); return FAIL; } --- 211,222 ---- if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) { ! semsg(_(e_invalid_line_number_nr), (long)start_lnum); return FAIL; } if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) { ! semsg(_(e_invalid_line_number_nr), (long)end_lnum); return FAIL; } *************** *** 243,249 **** col = 1; if (col - 1 > (colnr_T)textlen) { ! semsg(_(e_invalid_col), (long)start_col); return FAIL; } --- 241,247 ---- col = 1; if (col - 1 > (colnr_T)textlen) { ! semsg(_(e_invalid_column_number_nr), (long)start_col); return FAIL; } *** ../vim-8.2.3915/src/errors.h 2021-12-26 20:20:29.093631230 +0000 --- src/errors.h 2021-12-27 19:55:35.503111694 +0000 *************** *** 357,362 **** --- 357,366 ---- EXTERN char e_cannot_index_special_variable[] INIT(= N_("E909: Cannot index a special variable")); #endif + EXTERN char_u e_invalid_column_number_nr[] + INIT(= N_("E964: Invalid column number: %ld")); + EXTERN char_u e_invalid_line_number_nr[] + INIT(= N_("E966: Invalid line number: %ld")); EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[] INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s")); #ifdef FEAT_EVAL *** ../vim-8.2.3915/src/indent.c 2021-09-04 20:20:37.895881447 +0100 --- src/indent.c 2021-12-27 20:25:58.945346548 +0000 *************** *** 2130,2136 **** --- 2130,2140 ---- if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count) rettv->vval.v_number = get_indent_lnum(lnum); else + { + if (in_vim9script()) + semsg(_(e_invalid_line_number_nr), lnum); rettv->vval.v_number = -1; + } } /* *************** *** 2154,2159 **** --- 2158,2165 ---- rettv->vval.v_number = get_lisp_indent(); curwin->w_cursor = pos; } + else if (in_vim9script()) + semsg(_(e_invalid_line_number_nr), lnum); else #endif rettv->vval.v_number = -1; *** ../vim-8.2.3915/src/eval.c 2021-12-19 15:17:16.217857772 +0000 --- src/eval.c 2021-12-27 20:53:31.607855449 +0000 *************** *** 5359,5366 **** name = tv_get_string_chk(varp); if (name == NULL) return NULL; ! if (name[0] == '.') // cursor { pos = curwin->w_cursor; if (charcol) pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); --- 5359,5367 ---- name = tv_get_string_chk(varp); if (name == NULL) return NULL; ! if (name[0] == '.' && (!in_vim9script() || name[1] == NUL)) { + // cursor pos = curwin->w_cursor; if (charcol) pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); *************** *** 5376,5383 **** pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); return &pos; } ! if (name[0] == '\'') // mark { pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) return NULL; --- 5377,5386 ---- pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); return &pos; } ! if (name[0] == '\'' && (!in_vim9script() ! || (name[1] != NUL && name[2] == NUL))) { + // mark pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) return NULL; *** ../vim-8.2.3915/src/testdir/test_vim9_builtin.vim 2021-12-27 12:29:14.538581864 +0000 --- src/testdir/test_vim9_builtin.vim 2021-12-27 20:54:02.223782432 +0000 *************** *** 182,187 **** --- 182,190 ---- assert_equal("function('min')", getline(1)) CheckDefAndScriptFailure(['append([1], "x")'], ['E1013: Argument 1: type mismatch, expected string but got list', 'E1220: String or Number required for argument 1']) CheckDefExecAndScriptFailure(['append("", "x")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['append(".a", "x")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['append("''aa", "x")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['append(-1, "x")'], 'E966: Invalid line number: -1') bwipe! enddef *************** *** 199,204 **** --- 202,208 ---- assert_equal(['zero'], getbufline(bnum, 1)) CheckDefAndScriptFailure(['appendbufline([1], 1, "x")'], ['E1013: Argument 1: type mismatch, expected string but got list', 'E1220: String or Number required for argument 1']) CheckDefAndScriptFailure(['appendbufline(1, [1], "x")'], ['E1013: Argument 2: type mismatch, expected string but got list', 'E1220: String or Number required for argument 2']) + CheckDefExecAndScriptFailure(['appendbufline(' .. bnum .. ', -1, "x")'], 'E966: Invalid line number: -1') CheckDefAndScriptFailure(['appendbufline(1, 1, {"a": 10})'], ['E1013: Argument 3: type mismatch, expected string but got dict', 'E1224: String, Number or List required for argument 3']) bnum->bufwinid()->win_gotoid() appendbufline('', 0, 'numbers') *************** *** 1834,1839 **** --- 1838,1844 ---- CheckDefAndScriptFailure(['indent([1])'], ['E1013: Argument 1: type mismatch, expected string but got list', 'E1220: String or Number required for argument 1']) CheckDefAndScriptFailure(['indent(true)'], ['E1013: Argument 1: type mismatch, expected string but got bool', 'E1220: String or Number required for argument 1']) CheckDefExecAndScriptFailure(['indent("")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['indent(-1)'], 'E966: Invalid line number: -1') assert_equal(0, indent(1)) enddef *************** *** 2061,2066 **** --- 2066,2072 ---- def Test_lispindent() CheckDefAndScriptFailure(['lispindent({})'], ['E1013: Argument 1: type mismatch, expected string but got dict', 'E1220: String or Number required for argument 1']) CheckDefExecAndScriptFailure(['lispindent("")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['lispindent(-1)'], 'E966: Invalid line number: -1') assert_equal(0, lispindent(1)) enddef *************** *** 3239,3244 **** --- 3245,3251 ---- assert_equal(['1', '2', '3', 'one', '10', 'two', '11'], getbufline(bnum, 1, '$')) CheckDefAndScriptFailure(['setbufline([1], 1, "x")'], ['E1013: Argument 1: type mismatch, expected string but got list', 'E1220: String or Number required for argument 1']) CheckDefAndScriptFailure(['setbufline(1, [1], "x")'], ['E1013: Argument 2: type mismatch, expected string but got list', 'E1220: String or Number required for argument 2']) + CheckDefExecAndScriptFailure(['setbufline(' .. bnum .. ', -1, "x")'], 'E966: Invalid line number: -1') CheckDefAndScriptFailure(['setbufline(1, 1, {"a": 10})'], ['E1013: Argument 3: type mismatch, expected string but got dict', 'E1224: String, Number or List required for argument 3']) bnum->bufwinid()->win_gotoid() setbufline('', 1, 'nombres') *************** *** 3303,3308 **** --- 3310,3316 ---- assert_equal(['10', 'b', 'c', 'd'], getline(1, '$')) CheckDefAndScriptFailure(['setline([1], "x")'], ['E1013: Argument 1: type mismatch, expected string but got list', 'E1220: String or Number required for argument 1']) CheckDefExecAndScriptFailure(['setline("", "x")'], 'E1209: Invalid value for a line number') + CheckDefExecAndScriptFailure(['setline(-1, "x")'], 'E966: Invalid line number: -1') bw! enddef *** ../vim-8.2.3915/src/version.c 2021-12-27 19:28:34.005419704 +0000 --- src/version.c 2021-12-27 20:55:50.531539607 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3916, /**/ -- hundred-and-one symptoms of being an internet addict: 123. You ask the car dealer to install an extra cigarette lighter on your new car to power your notebook. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///