From 00e977cb83625f979d13639249a7788d5a1cb71e Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Wed, 1 Jun 2022 12:31:53 +0100 Subject: [PATCH 1/4] patch 8.2.5049: insufficient tests for autocommands Problem: Insufficient tests for autocommands. Solution: Add a few more tests. (Yegappan Lakshmanan, closes #10507) --- src/autocmd.c | 40 ++++++++++++++---------------------- src/testdir/gen_opt_test.vim | 2 +- src/testdir/test_autocmd.vim | 10 +++++++++ src/testdir/test_cmdline.vim | 9 ++++++++ src/version.c | 2 ++ 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/autocmd.c b/src/autocmd.c index 143891c9b8..2050da6640 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -3161,33 +3161,23 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv) for (ac = ap->cmds; ac != NULL; ac = ac->next) { event_dict = dict_alloc(); - if (event_dict == NULL) + if (event_dict == NULL + || list_append_dict(event_list, event_dict) == FAIL) return; - if (list_append_dict(event_list, event_dict) == FAIL) - return; - - if (dict_add_string(event_dict, "event", event_name) == FAIL) - return; - - if (dict_add_string(event_dict, "group", group_name == NULL - ? (char_u *)"" : group_name) == FAIL) - return; - - if (ap->buflocal_nr != 0) - if (dict_add_number(event_dict, "bufnr", ap->buflocal_nr) - == FAIL) - return; - - if (dict_add_string(event_dict, "pattern", ap->pat) == FAIL) - return; - - if (dict_add_string(event_dict, "cmd", ac->cmd) == FAIL) - return; - - if (dict_add_bool(event_dict, "once", ac->once) == FAIL) - return; - if (dict_add_bool(event_dict, "nested", ac->nested) == FAIL) + if (dict_add_string(event_dict, "event", event_name) == FAIL + || dict_add_string(event_dict, "group", + group_name == NULL ? (char_u *)"" + : group_name) == FAIL + || (ap->buflocal_nr != 0 + && (dict_add_number(event_dict, "bufnr", + ap->buflocal_nr) == FAIL)) + || dict_add_string(event_dict, "pattern", + ap->pat) == FAIL + || dict_add_string(event_dict, "cmd", ac->cmd) == FAIL + || dict_add_bool(event_dict, "once", ac->once) == FAIL + || dict_add_bool(event_dict, "nested", + ac->nested) == FAIL) return; } } diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim index c37631c66c..83f43f7b57 100644 --- a/src/testdir/gen_opt_test.vim +++ b/src/testdir/gen_opt_test.vim @@ -90,7 +90,7 @@ let test_values = { \ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']], \ 'eadirection': [['', 'both', 'ver'], ['xxx', 'ver,hor']], \ 'encoding': [['latin1'], ['xxx', '']], - \ 'eventignore': [['', 'WinEnter', 'WinLeave,winenter'], ['xxx']], + \ 'eventignore': [['', 'WinEnter', 'WinLeave,winenter', 'all,WinEnter'], ['xxx']], \ 'fileencoding': [['', 'latin1', 'xxx'], []], \ 'fileformat': [['', 'dos', 'unix'], ['xxx']], \ 'fileformats': [['', 'dos', 'dos,unix'], ['xxx']], diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 0aaa968c88..1a4ed1a624 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -3384,6 +3384,12 @@ func Test_autocmd_add() let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999, \ cmd: 'echo "bufadd"'}] call assert_fails("echo autocmd_add(l)", 'E680:') + let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999, + \ pattern: '*.py', cmd: 'echo "bufadd"'}] + call assert_fails("echo autocmd_add(l)", 'E680:') + let l = [#{group: 'TestAcSet', event: 'BufAdd', bufnr: 9999, + \ pattern: ['*.py', '*.c'], cmd: 'echo "bufadd"'}] + call assert_fails("echo autocmd_add(l)", 'E680:') let l = [#{group: 'TestAcSet', event: 'BufRead', bufnr: [], \ cmd: 'echo "bufread"'}] call assert_fails("echo autocmd_add(l)", 'E745:') @@ -3479,6 +3485,7 @@ func Test_autocmd_add() " Test for invalid values for 'pattern' item let l = [#{group: 'TestAcSet', event: "BufEnter", \ pattern: test_null_string(), cmd: 'echo "bufcmds"'}] + call assert_fails('call autocmd_add(l)', 'E928:') let l = [#{group: 'TestAcSet', event: "BufEnter", \ pattern: test_null_list(), cmd: 'echo "bufcmds"'}] call assert_fails('call autocmd_add(l)', 'E714:') @@ -3555,6 +3562,9 @@ func Test_autocmd_delete() " Delete a non-existing autocmd pattern let l = [#{group: 'TestAcSet', event: 'BufAdd', pat: 'abc'}] call assert_true(autocmd_delete(l)) + " Delete an autocmd for a non-existing buffer + let l = [#{event: '*', bufnr: 9999, cmd: 'echo "x"'}] + call assert_fails('call autocmd_delete(l)', 'E680:') " Delete an autocmd group augroup TestAcSet diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index cc7fe54d60..77965b3f65 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -1063,10 +1063,19 @@ func Test_cmdline_complete_various() augroup END call feedkeys(":augroup X\\\"\", 'xt') call assert_equal("\"augroup XTest.test", @:) + + " group name completion in :autocmd call feedkeys(":au X\\\"\", 'xt') call assert_equal("\"au XTest.test", @:) + call feedkeys(":au XTest.test\\\"\", 'xt') + call assert_equal("\"au XTest.test", @:) + augroup! XTest.test + " autocmd pattern completion + call feedkeys(":au BufEnter *.py\\\"\", 'xt') + call assert_equal("\"au BufEnter *.py\t", @:) + " completion for the :unlet command call feedkeys(":unlet one two\\\"\", 'xt') call assert_equal("\"unlet one two", @:) diff --git a/src/version.c b/src/version.c index ac335516b3..97ca8ce5cb 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 5049, /**/ 5048, /**/ From 409510c588b1eec1ae33511ae97a21eb8e110895 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 1 Jun 2022 15:23:13 +0100 Subject: [PATCH 2/4] patch 8.2.5050: using freed memory when searching for pattern in path Problem: Using freed memory when searching for pattern in path. Solution: Make a copy of the line. --- src/search.c | 21 ++++++++++++++++++--- src/testdir/test_tagjump.vim | 11 +++++++++++ src/version.c | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/search.c b/src/search.c index ea72ec7fb9..35dc89b8fe 100644 --- a/src/search.c +++ b/src/search.c @@ -3305,6 +3305,21 @@ update_search_stat( } #if defined(FEAT_FIND_ID) || defined(PROTO) + +/* + * Get line "lnum" and copy it into "buf[LSIZE]". + * The copy is made because the regexp may make the line invalid when using a + * mark. + */ + static char_u * +get_line_and_copy(linenr_T lnum, char_u *buf) +{ + char_u *line = ml_get(lnum); + + vim_strncpy(buf, line, LSIZE - 1); + return buf; +} + /* * Find identifiers or defines in included files. * If p_ic && compl_status_sol() then ptr must be in lowercase. @@ -3409,7 +3424,7 @@ find_pattern_in_path( end_lnum = curbuf->b_ml.ml_line_count; if (lnum > end_lnum) // do at least one line lnum = end_lnum; - line = ml_get(lnum); + line = get_line_and_copy(lnum, file_line); for (;;) { @@ -3738,7 +3753,7 @@ search_line: { if (lnum >= end_lnum) goto exit_matched; - line = ml_get(++lnum); + line = get_line_and_copy(++lnum, file_line); } else if (vim_fgets(line = file_line, LSIZE, files[depth].fp)) @@ -3950,7 +3965,7 @@ exit_matched: { if (++lnum > end_lnum) break; - line = ml_get(lnum); + line = get_line_and_copy(lnum, file_line); } already = NULL; } diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim index aacfb9baeb..060cc3b188 100644 --- a/src/testdir/test_tagjump.vim +++ b/src/testdir/test_tagjump.vim @@ -1290,6 +1290,17 @@ func Test_inc_search() close! endfunc +" this was using a line from ml_get() freed by the regexp +func Test_isearch_copy_line() + new + norm o + norm 0 + 0norm o + sil! norm bc0 + sil! isearch \%') + bwipe! +endfunc + " Test for :dsearch, :dlist, :djump and :dsplit commands " Test for [d, ]d, [D, ]D, [ CTRL-D, ] CTRL-D and CTRL-W d commands func Test_macro_search() diff --git a/src/version.c b/src/version.c index 97ca8ce5cb..ba8688bc55 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 5050, /**/ 5049, /**/ From 882476ad7b4944a8386993e94b7e31139a314f91 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 1 Jun 2022 16:02:38 +0100 Subject: [PATCH 3/4] patch 8.2.5051: check for autocmd_add() event argument is confusing Problem: Check for autocmd_add() event argument is confusing. Solution: Make the code more straightforward. --- src/autocmd.c | 14 ++++++-------- src/version.c | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/autocmd.c b/src/autocmd.c index 2050da6640..71aeb5036b 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -2951,26 +2951,24 @@ autocmd_add_or_delete(typval_T *argvars, typval_T *rettv, int delete) if (eli == NULL) break; if (eli->li_tv.v_type != VAR_STRING - || eli->li_tv.vval.v_string == NULL) + || (p = eli->li_tv.vval.v_string) == NULL) { emsg(_(e_string_required)); - continue; + break; } - p = eli->li_tv.vval.v_string; } else { - if (end == NULL) - p = end = event_name; - if (end == NULL || *end == NUL) + if (p == NULL) + p = event_name; + if (p == NULL || *p == NUL) break; } - if (p == NULL) - continue; event = event_name2nr(p, &end); if (event == NUM_EVENTS || *end != NUL) { + // this also catches something following a valid event name semsg(_(e_no_such_event_str), p); retval = VVAL_FALSE; break; diff --git a/src/version.c b/src/version.c index ba8688bc55..9df41679b4 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 5051, /**/ 5050, /**/ From bfaa24f95343af9c058696644375d04e660f1b00 Mon Sep 17 00:00:00 2001 From: Philip H <47042125+pheiduck@users.noreply.github.com> Date: Wed, 1 Jun 2022 21:26:34 +0100 Subject: [PATCH 4/4] patch 8.2.5052: CI checkout step title is a bit cryptic Problem: CI checkout step title is a bit cryptic. Solution: Add a better title. (closes #10509) --- .github/workflows/ci.yml | 9 ++++++--- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/coverity.yml | 3 ++- src/version.c | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62be12dda4..194143040b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,8 @@ jobs: extra: vimtags steps: - - uses: actions/checkout@v3 + - name: Checkout repository from github + uses: actions/checkout@v3 - name: Install packages run: | @@ -295,7 +296,8 @@ jobs: features: [tiny, normal, huge] steps: - - uses: actions/checkout@v3 + - name: Checkout repository from github + uses: actions/checkout@v3 - name: Install packages if: matrix.features == 'huge' @@ -432,7 +434,8 @@ jobs: msystem: ${{ matrix.msystem }} release: false - - uses: actions/checkout@v3 + - name: Checkout repository from github + uses: actions/checkout@v3 - name: Create a list of download URLs shell: cmd diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6b9db03492..efb9e66995 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -36,7 +36,7 @@ jobs: # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection steps: - - name: Checkout repository + - name: Checkout repository from github uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 7d9341e969..a58a20b615 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -13,7 +13,8 @@ jobs: DEBIAN_FRONTEND: noninteractive steps: - - uses: actions/checkout@v3 + - name: Checkout repository from github + uses: actions/checkout@v3 - name: Download Coverity run: | diff --git a/src/version.c b/src/version.c index 9df41679b4..36a69d922c 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 5052, /**/ 5051, /**/