diff options
-rwxr-xr-x | scripts/vim-patch.sh | 51 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 39 | ||||
-rw-r--r-- | src/nvim/testdir/test_alot.vim | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_ex_z.vim | 78 |
4 files changed, 129 insertions, 42 deletions
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index 5182756d83..95293f9572 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -37,11 +37,11 @@ usage() { } msg_ok() { - printf "\e[32m✔\e[0m $@\n" + printf '\e[32m✔\e[0m %s\n' "$@" } msg_err() { - printf "\e[31m✘\e[0m $@\n" + printf '\e[31m✘\e[0m %s\n' "$@" } # Checks if a program is in the user's PATH, and is executable. @@ -218,7 +218,7 @@ stage_patch() { msg_ok "Current branch '${checked_out_branch}' seems to be a vim-patch" echo " branch; not creating a new branch." else - printf "\nFetching '${git_remote}/master'.\n" + printf '\nFetching "%s/master".\n' "${git_remote}" output="$(git fetch "${git_remote}" master 2>&1)" && msg_ok "${output}" || (msg_err "${output}"; false) @@ -248,21 +248,22 @@ stage_patch() { fi printf "\nInstructions:\n Proceed to port the patch.\n" else - printf "\nInstructions:\n Proceed to port the patch.\n Try the 'patch' command (or use '${BASENAME} -P ...' next time):\n patch -p1 < ${patch_file}\n" + printf '\nInstructions:\n Proceed to port the patch.\n Try the "patch" command (or use "%s -P ..." next time):\n patch -p1 < %s\n' "${BASENAME}" "${patch_file}" fi - printf " - Stage your changes ('git add ...'), then use 'git commit --amend' to commit. + printf ' + Stage your changes ("git add ..."), then use "git commit --amend" to commit. - To port more patches (if any) related to ${vim_version}, - run '${BASENAME}' again. + To port more patches (if any) related to %s, + run "%s" again. * Do this only for _related_ patches (otherwise it increases the size of the pull request, making it harder to review) - When you're done, try '${BASENAME} -s' to create the pull request. + When you are done, try "%s -s" to create the pull request. See the wiki for more information: - * https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim\n" + * https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim +' "${vim_version}" "${BASENAME}" "${BASENAME}" } hub_pr() { @@ -398,24 +399,24 @@ show_vimpatches() { list_missing_vimpatches | while read vim_commit; do if (cd "${VIM_SOURCE_DIR}" && git --no-pager show --color=never --name-only "v${vim_commit}" 2>/dev/null) | grep -q ^runtime; then - printf " • ${vim_commit} (+runtime)\n" + printf ' • %s (+runtime)\n' "${vim_commit}" else - printf " • ${vim_commit}\n" + printf ' • %s\n' "${vim_commit}" fi done - echo - echo "Instructions:" - echo - echo " To port one of the above patches to Neovim, execute" - echo " this script with the patch revision as argument and" - echo " follow the instructions." - echo - echo " Examples: '${BASENAME} -p 7.4.487'" - echo " '${BASENAME} -p 1e8ebf870720e7b671f98f22d653009826304c4f'" - echo - echo " NOTE: Please port the _oldest_ patch if you possibly can." - echo " Out-of-order patches increase the possibility of bugs." + printf "Instructions: + + To port one of the above patches to Neovim, execute + this script with the patch revision as argument and + follow the instructions. + + Examples: '%s -p 7.4.487' + '%s -p 1e8ebf870720e7b671f98f22d653009826304c4f' + + NOTE: Please port the _oldest_ patch if you possibly can. + Out-of-order patches increase the possibility of bugs. +" "${BASENAME}" "${BASENAME}" } review_commit() { @@ -436,7 +437,7 @@ review_commit() { echo " This script assumes that the PR contains only commits" echo " with 'vim-patch:XXX' in their title." echo - printf -- "$(head -n 4 <<< "${nvim_patch}")\n\n" + printf -- '%s\n\n' "$(head -n 4 <<< "${nvim_patch}")" local reply read -p "Continue reviewing (y/N)? " -n 1 -r reply if [[ "${reply}" == y ]]; then diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 98eda8dcb8..d58d006dd0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1306,10 +1306,10 @@ filterend: * Call a shell to execute a command. * When "cmd" is NULL start an interactive shell. */ -void -do_shell ( +void +do_shell( char_u *cmd, - int flags /* may be SHELL_DOOUT when output is redirected */ + int flags // may be SHELL_DOOUT when output is redirected ) { int save_nwr; @@ -1789,14 +1789,14 @@ theend: * May set eap->forceit if a dialog says it's OK to overwrite. * Return OK if it's OK, FAIL if it is not. */ -int -check_overwrite ( +int +check_overwrite( exarg_T *eap, buf_T *buf, - char_u *fname, /* file name to be used (can differ from - buf->ffname) */ - char_u *ffname, /* full path version of fname */ - int other /* writing under other name */ + char_u *fname, // file name to be used (can differ from + // buf->ffname) + char_u *ffname, // full path version of fname + int other // writing under other name ) { /* @@ -2823,7 +2823,7 @@ void ex_change(exarg_T *eap) void ex_z(exarg_T *eap) { char_u *x; - int bigness; + int64_t bigness; char_u *kind; int minus = 0; linenr_T start, end, curs, i; @@ -2856,10 +2856,17 @@ void ex_z(exarg_T *eap) EMSG(_("E144: non-numeric argument to :z")); return; } - bigness = atoi((char *)x); + bigness = atol((char *)x); + + // bigness could be < 0 if atol(x) overflows. + if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) { + bigness = 2 * curbuf->b_ml.ml_line_count; + } + p_window = bigness; - if (*kind == '=') + if (*kind == '=') { bigness += 2; + } } /* the number of '-' and '+' multiplies the distance */ @@ -4587,11 +4594,11 @@ char_u *check_help_lang(char_u *arg) * Assumption is made that the matched_string passed has already been found to * match some string for which help is requested. webb. */ -int -help_heuristic ( +int +help_heuristic( char_u *matched_string, - int offset, /* offset for match */ - int wrong_case /* no matching case */ + int offset, // offset for match + int wrong_case // no matching case ) { int num_letters; diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index c4b4a43ad4..71f3ad1bc0 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -5,6 +5,7 @@ source test_assign.vim source test_changedtick.vim source test_cursor_func.vim source test_ex_undo.vim +source test_ex_z.vim source test_execute_func.vim source test_expr.vim source test_feedkeys.vim @@ -19,8 +20,8 @@ source test_jumps.vim source test_fileformat.vim source test_filetype.vim source test_lambda.vim -source test_menu.vim source test_mapping.vim +source test_menu.vim source test_messages.vim source test_partial.vim source test_popup.vim diff --git a/src/nvim/testdir/test_ex_z.vim b/src/nvim/testdir/test_ex_z.vim new file mode 100644 index 0000000000..608a36c490 --- /dev/null +++ b/src/nvim/testdir/test_ex_z.vim @@ -0,0 +1,78 @@ +" Test :z + +func Test_z() + call setline(1, range(1, 100)) + + let a = execute('20z3') + call assert_equal("\n20\n21\n22", a) + call assert_equal(22, line('.')) + " 'window' should be set to the {count} value. + call assert_equal(3, &window) + + " If there is only one window, then twice the amount of 'scroll' is used. + set scroll=2 + let a = execute('20z') + call assert_equal("\n20\n21\n22\n23", a) + call assert_equal(23, line('.')) + + let a = execute('20z+3') + " FIXME: I would expect the same result as '20z3' but it + " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"? + "call assert_equal("\n20\n21\n22", a) + "call assert_equal(22, line('.')) + + let a = execute('20z-3') + call assert_equal("\n18\n19\n20", a) + call assert_equal(20, line('.')) + + let a = execute('20z=3') + call assert_match("^\n18\n19\n-\\+\n20\n-\\+\n21\n22$", a) + call assert_equal(20, line('.')) + + let a = execute('20z^3') + call assert_equal("\n14\n15\n16\n17", a) + call assert_equal(17, line('.')) + + let a = execute('20z.3') + call assert_equal("\n19\n20\n21", a) + call assert_equal(21, line('.')) + + let a = execute('20z#3') + call assert_equal("\n 20 20\n 21 21\n 22 22", a) + call assert_equal(22, line('.')) + + let a = execute('20z#-3') + call assert_equal("\n 18 18\n 19 19\n 20 20", a) + call assert_equal(20, line('.')) + + let a = execute('20z#=3') + call assert_match("^\n 18 18\n 19 19\n-\\+\n 20 20\n-\\+\n 21 21\n 22 22$", a) + call assert_equal(20, line('.')) + + " Test with {count} bigger than the number of lines in buffer. + let a = execute('20z1000') + call assert_match("^\n20\n21\n.*\n99\n100$", a) + call assert_equal(100, line('.')) + + let a = execute('20z-1000') + call assert_match("^\n1\n2\n.*\n19\n20$", a) + call assert_equal(20, line('.')) + + let a = execute('20z=1000') + call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a) + call assert_equal(20, line('.')) + + call assert_fails('20z=a', 'E144:') + + set window& scroll& + bw! +endfunc + +func Test_z_bug() + " This used to access invalid memory as a result of an integer overflow + " and freeze vim. + normal ox + normal Heat + z777777776666666 + ') +endfunc |