From 04de6a64e2f7b3b235acd4ab779bfed30e59451f Mon Sep 17 00:00:00 2001 From: ckelsel Date: Fri, 7 Jul 2017 14:57:50 +0800 Subject: vim-patch:7.4.2189 https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6 Author: Bram Moolenaar Date: Tue Aug 9 22:14:05 2016 +0200 patch 7.4.2189 Problem: Cannot detect encoding in a fifo. Solution: Extend the stdin way of detecting encoding to fifo. Add a test for detecting encoding on stdin and fifo. (Ken Takata) --- src/nvim/fileio.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index be4188c4df..dcef09e21f 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -247,6 +247,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) * stdin) * READ_DUMMY read into a dummy buffer (to check if file contents changed) * READ_KEEP_UNDO don't clear undo info or read it from a file + * READ_FIFO read from fifo/socket instead of a file * * return FAIL for failure, NOTDONE for directory (failure), or OK */ @@ -267,6 +268,7 @@ readfile ( int filtering = (flags & READ_FILTER); int read_stdin = (flags & READ_STDIN); int read_buffer = (flags & READ_BUFFER); + int read_fifo = (flags & READ_FIFO); int set_options = newfile || read_buffer || (eap != NULL && eap->read_edit); linenr_T read_buf_lnum = 1; /* next line to read from curbuf */ @@ -426,7 +428,7 @@ readfile ( } } - if (!read_buffer && !read_stdin) { + if (!read_buffer && !read_stdin && !read_fifo) { perm = os_getperm((const char *)fname); #ifdef UNIX // On Unix it is possible to read a directory, so we have to @@ -468,7 +470,7 @@ readfile ( if (check_readonly && !readonlymode) curbuf->b_p_ro = FALSE; - if (newfile && !read_stdin && !read_buffer) { + if (newfile && !read_stdin && !read_buffer && !read_fifo) { /* Remember time of file. */ FileInfo file_info; if (os_fileinfo((char *)fname, &file_info)) { @@ -895,6 +897,7 @@ retry: * and we can't do it internally or with iconv(). */ if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL + && !read_fifo # ifdef USE_ICONV && iconv_fd == (iconv_t)-1 # endif @@ -935,7 +938,7 @@ retry: /* Set "can_retry" when it's possible to rewind the file and try with * another "fenc" value. It's FALSE when no other "fenc" to try, reading * stdin or fixed at a specific encoding. */ - can_retry = (*fenc != NUL && !read_stdin && !keep_dest_enc); + can_retry = (*fenc != NUL && !read_stdin && !keep_dest_enc && !read_fifo); if (!skip_read) { linerest = 0; @@ -947,6 +950,7 @@ retry: && curbuf->b_ffname != NULL && curbuf->b_p_udf && !filtering + && !read_fifo && !read_stdin && !read_buffer); if (read_undo_file) @@ -1919,7 +1923,7 @@ failed: u_read_undo(NULL, hash, fname); } - if (!read_stdin && !read_buffer) { + if (!read_stdin && !read_fifo && (!read_buffer || sfname != NULL)) { int m = msg_scroll; int n = msg_scrolled; @@ -1937,7 +1941,7 @@ failed: if (filtering) { apply_autocmds_exarg(EVENT_FILTERREADPOST, NULL, sfname, false, curbuf, eap); - } else if (newfile) { + } else if (newfile || (read_buffer && sfname != NULL)) { apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname, false, curbuf, eap); if (!au_did_filetype && *curbuf->b_p_ft != NUL) { -- cgit From 2999d7c0e89087f76711e914eb65af55578a6691 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Mon, 10 Jul 2017 07:58:40 +0800 Subject: vim-patch:7.4.2229 https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f Author: Bram Moolenaar Date: Sat Aug 20 15:05:39 2016 +0200 patch 7.4.2229 Problem: Startup test fails on Solaris. Solution: Recognize a character device. (Danek Duvall) --- src/nvim/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index dcef09e21f..41117fdd3d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1974,7 +1974,7 @@ failed: /// Do not accept "/dev/fd/[012]", opening these may hang Vim. /// /// @param fname file name to check -static bool is_dev_fd_file(char_u *fname) +bool is_dev_fd_file(char_u *fname) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { return STRNCMP(fname, "/dev/fd/", 8) == 0 -- cgit From 462a6148a64f2c2faabdee1eacac273ddbbd095a Mon Sep 17 00:00:00 2001 From: ckelsel Date: Tue, 11 Jul 2017 09:07:18 +0800 Subject: lint --- src/nvim/fileio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 41117fdd3d..a0536d456d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -268,7 +268,7 @@ readfile ( int filtering = (flags & READ_FILTER); int read_stdin = (flags & READ_STDIN); int read_buffer = (flags & READ_BUFFER); - int read_fifo = (flags & READ_FIFO); + int read_fifo = (flags & READ_FIFO); int set_options = newfile || read_buffer || (eap != NULL && eap->read_edit); linenr_T read_buf_lnum = 1; /* next line to read from curbuf */ @@ -471,7 +471,7 @@ readfile ( curbuf->b_p_ro = FALSE; if (newfile && !read_stdin && !read_buffer && !read_fifo) { - /* Remember time of file. */ + // Remember time of file. FileInfo file_info; if (os_fileinfo((char *)fname, &file_info)) { buf_store_file_info(curbuf, &file_info); -- cgit From 9506ee037083ff047a3601b3d97acf91521a58fb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 8 Aug 2017 20:50:41 +0200 Subject: buf_write(): wrong argument to os_fileinfo_hardlinks This was broken in ye olde refactor from 2014: e85fe0957d40080f43cbfcbe9eb8864475325b09 References #4370 --- src/nvim/fileio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a0536d456d..643020df5e 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -3162,8 +3162,8 @@ nobackup: #ifdef UNIX FileInfo file_info; - /* Don't delete the file when it's a hard or symbolic link. */ - if ((!newfile && os_fileinfo_hardlinks(&file_info) > 1) + // Don't delete the file when it's a hard or symbolic link. + if ((!newfile && os_fileinfo_hardlinks(&file_info_old) > 1) || (os_fileinfo_link((char *)fname, &file_info) && !os_fileinfo_id_equal(&file_info, &file_info_old))) { SET_ERRMSG(_("E166: Can't open linked file for writing")); @@ -4547,6 +4547,7 @@ int put_time(FILE *fd, time_t time_) /// /// @return -1 for failure, 0 for success int vim_rename(const char_u *from, const char_u *to) + FUNC_ATTR_NONNULL_ALL { int fd_in; int fd_out; @@ -4822,6 +4823,7 @@ buf_check_timestamp ( buf_T *buf, int focus /* called for GUI focus event */ ) + FUNC_ATTR_NONNULL_ALL { int retval = 0; char_u *path; -- cgit From 7ae744b93d80fd169507732931606276844150b6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 10 Aug 2017 01:40:21 +0200 Subject: buf_write(): handle NULL fname on non-unix --- src/nvim/fileio.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 643020df5e..feb16f44d4 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2570,11 +2570,9 @@ buf_write ( perm = -1; } } -#else /* win32 */ - /* - * Check for a writable device name. - */ - c = os_nodetype((char *)fname); +#else // win32 + // Check for a writable device name. + c = fname == NULL ? NODE_OTHER : os_nodetype((char *)fname); if (c == NODE_OTHER) { SET_ERRMSG_NUM("E503", _("is not a file or writable device")); goto fail; @@ -2594,9 +2592,8 @@ buf_write ( if (overwriting) { os_fileinfo((char *)fname, &file_info_old); } - } -#endif /* !UNIX */ +#endif // !UNIX if (!device && !newfile) { /* -- cgit From 7e8212c459b285aacf2dd225c1dad5593314f094 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Fri, 10 Nov 2017 23:17:20 +0800 Subject: vim-patch:8.0.0224 Problem: When 'fileformats' is changed in a BufReadPre auto command, it does not take effect in readfile(). (Gary Johnson) Solution: Check the value of 'fileformats' after executing auto commands. (Christian Brabandt) https://github.com/vim/vim/commit/7a2699e868bca781e26b060a44fc714d87cfa4ba --- src/nvim/fileio.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index feb16f44d4..81ac98081d 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -302,11 +302,11 @@ readfile ( linenr_T skip_count = 0; linenr_T read_count = 0; int msg_save = msg_scroll; - linenr_T read_no_eol_lnum = 0; /* non-zero lnum when last line of - * last read was missing the eol */ - int try_mac = (vim_strchr(p_ffs, 'm') != NULL); - int try_dos = (vim_strchr(p_ffs, 'd') != NULL); - int try_unix = (vim_strchr(p_ffs, 'x') != NULL); + linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of + // last read was missing the eol + int try_mac; + int try_dos; + int try_unix; int file_rewind = FALSE; int can_retry; linenr_T conv_error = 0; /* line nr with conversion error */ @@ -639,6 +639,10 @@ readfile ( curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); curbuf->b_op_start.col = 0; + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); + if (!read_buffer) { int m = msg_scroll; int n = msg_scrolled; @@ -668,6 +672,12 @@ readfile ( else apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, FALSE, NULL, eap); + + // autocommands may have changed it + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); + if (msg_scrolled == n) msg_scroll = m; -- cgit From ea020f2e26f1e5cb89eb632c1b0ee51daf7718b4 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Sat, 11 Nov 2017 09:04:48 +0800 Subject: fix lint error --- src/nvim/fileio.c | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 81ac98081d..c3a0a33378 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -307,7 +307,7 @@ readfile ( int try_mac; int try_dos; int try_unix; - int file_rewind = FALSE; + int file_rewind = false; int can_retry; linenr_T conv_error = 0; /* line nr with conversion error */ linenr_T illegal_byte = 0; /* line nr with illegal byte */ @@ -647,39 +647,38 @@ readfile ( int m = msg_scroll; int n = msg_scrolled; - /* - * The file must be closed again, the autocommands may want to change - * the file before reading it. - */ - if (!read_stdin) - close(fd); /* ignore errors */ + // The file must be closed again, the autocommands may want to change + // the file before reading it. + if (!read_stdin) { + close(fd); // ignore errors + } - /* - * The output from the autocommands should not overwrite anything and - * should not be overwritten: Set msg_scroll, restore its value if no - * output was done. - */ - msg_scroll = TRUE; - if (filtering) + // The output from the autocommands should not overwrite anything and + // should not be overwritten: Set msg_scroll, restore its value if no + // output was done. + msg_scroll = true; + if (filtering) { apply_autocmds_exarg(EVENT_FILTERREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else if (read_stdin) + false, curbuf, eap); + } else if (read_stdin) { apply_autocmds_exarg(EVENT_STDINREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else if (newfile) + false, curbuf, eap); + } else if (newfile) { apply_autocmds_exarg(EVENT_BUFREADPRE, NULL, sfname, - FALSE, curbuf, eap); - else + false, curbuf, eap); + } else { apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, - FALSE, NULL, eap); + false, NULL, eap); + } - // autocommands may have changed it - try_mac = (vim_strchr(p_ffs, 'm') != NULL); - try_dos = (vim_strchr(p_ffs, 'd') != NULL); - try_unix = (vim_strchr(p_ffs, 'x') != NULL); + // autocommands may have changed it + try_mac = (vim_strchr(p_ffs, 'm') != NULL); + try_dos = (vim_strchr(p_ffs, 'd') != NULL); + try_unix = (vim_strchr(p_ffs, 'x') != NULL); - if (msg_scrolled == n) + if (msg_scrolled == n) { msg_scroll = m; + } if (aborting()) { /* autocmds may abort script processing */ --no_wait_return; -- cgit From 8fff2ef74aae47042c4ee903ae996aa789787fe1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Nov 2017 08:30:25 +0100 Subject: vim-patch:8.0.0227 (#7548) Problem: Crash when 'fileformat' is forced to "dos" and the first line in the file is empty and does not have a CR character. Solution: Don't check for CR before the start of the buffer. https://github.com/vim/vim/commit/2aa5f696b91a51f29873e340de4bdc182e1e8dd4 --- src/nvim/fileio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a7676e88f0..ae6c3f96e3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1622,7 +1622,8 @@ rewind_retry: *ptr = NUL; /* end of line */ len = (colnr_T)(ptr - line_start + 1); if (fileformat == EOL_DOS) { - if (ptr[-1] == CAR) { /* remove CR */ + if (ptr > line_start && ptr[-1] == CAR) { + // remove CR before NL ptr[-1] = NUL; len--; } else if (ff_error != EOL_DOS) { -- cgit From 0f9c90e0edd27d2db04d48e7bd98bb46d2c4a918 Mon Sep 17 00:00:00 2001 From: Matt Widmann Date: Sat, 25 Nov 2017 13:59:07 -0800 Subject: io: retry fgets on EINTR (#7632) The calls to `fgets` in `src/nvim/if_cscope.c` (and elsewhere) can show communication errors to the user if a signal is delivered during its system calls. For plugins that proxy subprocess output into cscope requests, a `SIGCHLD` might *always* interfere with calls into `fgets`. To see this in a debugger, put a breakpoint on `cs_reading_emsg` and watch signals come in (with lldb, using `process handle --notify true --pass true`). Next, run a subcommand from neovim that calls through cscope when it returns. A tag picker plugin, like vim-picker and fzy, with `cscopetag` and `cscopetagorder=0` set, reproduced this reliably. The breakpoint will hit after a `SIGCHLD` is delivered, and `errno` will be set to 4, `EINTR`. The caller of `fgets` should retry when `NULL` is returned with `errno` set to `EINTR`. --- src/nvim/fileio.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ae6c3f96e3..9214e1e644 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4448,7 +4448,12 @@ bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL char tbuf[FGETS_SIZE]; buf[size - 2] = NUL; +retry: + errno = 0; eof = fgets((char *)buf, size, fp); + if (eof == NULL && errno == EINTR) { + goto retry; + } if (buf[size - 2] != NUL && buf[size - 2] != '\n') { buf[size - 1] = NUL; /* Truncate the line */ -- cgit From bab2f8200aea09ad32bbcb2e83404bbd4076a227 Mon Sep 17 00:00:00 2001 From: Matt Widmann Date: Sat, 25 Nov 2017 13:27:59 -0800 Subject: io: fix handling EOF in vim_fgets If an EOF is returned from `fgets`, `vim_fgets` might spin forever, as it tries to consume the current line. A `NULL` return value from `fgets` should break out of the function (unless `errno` is `EINTR`), and then `feof` should be used to check for the EOF condition on the stream. --- src/nvim/fileio.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 9214e1e644..1f4cd22754 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4443,27 +4443,32 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) /// @return true for end-of-file. bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL { - char *eof; -#define FGETS_SIZE 200 - char tbuf[FGETS_SIZE]; + char *retval; + assert(size > 0); buf[size - 2] = NUL; -retry: - errno = 0; - eof = fgets((char *)buf, size, fp); - if (eof == NULL && errno == EINTR) { - goto retry; - } + + do { + errno = 0; + retval = fgets((char *)buf, size, fp); + } while (retval == NULL && errno == EINTR); + if (buf[size - 2] != NUL && buf[size - 2] != '\n') { - buf[size - 1] = NUL; /* Truncate the line */ + char tbuf[200]; + + buf[size - 1] = NUL; // Truncate the line. - /* Now throw away the rest of the line: */ + // Now throw away the rest of the line: do { - tbuf[FGETS_SIZE - 2] = NUL; - ignoredp = fgets((char *)tbuf, FGETS_SIZE, fp); - } while (tbuf[FGETS_SIZE - 2] != NUL && tbuf[FGETS_SIZE - 2] != '\n'); + tbuf[sizeof(tbuf) - 2] = NUL; + errno = 0; + retval = fgets((char *)tbuf, sizeof(tbuf), fp); + if (retval == NULL && errno != EINTR) { + break; + } + } while (tbuf[sizeof(tbuf) - 2] != NUL && tbuf[sizeof(tbuf) - 2] != '\n'); } - return eof == NULL; + return retval ? false : feof(fp); } /// Read 2 bytes from "fd" and turn them into an int, MSB first. -- cgit From 8728a5d50bc3339db81c7f29d59c55f9f817f06c Mon Sep 17 00:00:00 2001 From: KunMing Xie Date: Wed, 31 Jan 2018 03:29:15 +0800 Subject: vim-patch:8.0.0448: some macros are lower case (#7936) Problem: Some macros are in lower case, which can be confusing. Solution: Make a few lower case macros upper case. https://github.com/vim/vim/commit/b5aedf3e228d35821591da9ae8501b61cf2e264c ref #6297 --- src/nvim/fileio.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 1f4cd22754..44d74c92cd 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5088,14 +5088,12 @@ void buf_reload(buf_T *buf, int orig_mode) flags |= READ_KEEP_UNDO; } - /* - * To behave like when a new file is edited (matters for - * BufReadPost autocommands) we first need to delete the current - * buffer contents. But if reading the file fails we should keep - * the old contents. Can't use memory only, the file might be - * too big. Use a hidden buffer to move the buffer contents to. - */ - if (bufempty() || saved == FAIL) { + // To behave like when a new file is edited (matters for + // BufReadPost autocommands) we first need to delete the current + // buffer contents. But if reading the file fails we should keep + // the old contents. Can't use memory only, the file might be + // too big. Use a hidden buffer to move the buffer contents to. + if (BUFEMPTY() || saved == FAIL) { savebuf = NULL; } else { // Allocate a buffer without putting it in the buffer list. @@ -5128,7 +5126,7 @@ void buf_reload(buf_T *buf, int orig_mode) if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) { // Put the text back from the save buffer. First // delete any lines that readfile() added. - while (!bufempty()) { + while (!BUFEMPTY()) { if (ml_delete(buf->b_ml.ml_line_count, false) == FAIL) { break; } -- cgit From fd58863eb62edddf688a71d73448934efa188241 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 02:30:21 +0100 Subject: vim-patch:8.0.0703: illegal memory access with empty :doau command Problem: Illegal memory access with empty :doau command. Solution: Check the event for being out of range. (James McCoy) https://github.com/vim/vim/commit/faf29d7f91477c25c85d9d7165d90e8d8f1c512e --- src/nvim/fileio.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 44d74c92cd..54b0032c9c 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6274,13 +6274,13 @@ do_doautocmd ( fname = skipwhite(fname); - /* - * Loop over the events. - */ - while (*arg && !ascii_iswhite(*arg)) - if (apply_autocmds_group(event_name2nr(arg, &arg), - fname, NULL, TRUE, group, curbuf, NULL)) + // Loop over the events. + while (*arg && !ends_excmd(*arg) && !ascii_iswhite(*arg)) { + if (apply_autocmds_group(event_name2nr(arg, &arg), fname, NULL, TRUE, + group, curbuf, NULL)) { nothing_done = FALSE; + } + } if (nothing_done && do_msg) { MSG(_("No matching autocommands")); @@ -6671,12 +6671,12 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, proftime_T wait_time; bool did_save_redobuff = false; - /* - * Quickly return if there are no autocommands for this event or - * autocommands are blocked. - */ - if (first_autopat[(int)event] == NULL || autocmd_blocked > 0) + // Quickly return if there are no autocommands for this event or + // autocommands are blocked. + if (event == NUM_EVENTS || first_autopat[(int)event] == NULL + || autocmd_blocked > 0) { goto BYPASS_AU; + } /* * When autocommands are busy, new autocommands are only executed when @@ -6742,18 +6742,21 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, * invalid. */ if (fname_io == NULL) { - if (event == EVENT_COLORSCHEME || event == EVENT_OPTIONSET) + if (event == EVENT_COLORSCHEME || event == EVENT_OPTIONSET) { autocmd_fname = NULL; - else if (fname != NULL && *fname != NUL) + } else if (fname != NULL && !ends_excmd(*fname)) { autocmd_fname = fname; - else if (buf != NULL) + } else if (buf != NULL) { autocmd_fname = buf->b_ffname; - else + } else { autocmd_fname = NULL; - } else + } + } else { autocmd_fname = fname_io; - if (autocmd_fname != NULL) + } + if (autocmd_fname != NULL) { autocmd_fname = vim_strsave(autocmd_fname); + } autocmd_fname_full = FALSE; /* call FullName_save() later */ /* -- cgit From f26a4d484b486019c90fc55af5e74e33de374bc4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Feb 2018 19:02:57 +0100 Subject: lint --- src/nvim/fileio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 54b0032c9c..91b0a695f1 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6276,9 +6276,9 @@ do_doautocmd ( // Loop over the events. while (*arg && !ends_excmd(*arg) && !ascii_iswhite(*arg)) { - if (apply_autocmds_group(event_name2nr(arg, &arg), fname, NULL, TRUE, + if (apply_autocmds_group(event_name2nr(arg, &arg), fname, NULL, true, group, curbuf, NULL)) { - nothing_done = FALSE; + nothing_done = false; } } @@ -6757,7 +6757,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, if (autocmd_fname != NULL) { autocmd_fname = vim_strsave(autocmd_fname); } - autocmd_fname_full = FALSE; /* call FullName_save() later */ + autocmd_fname_full = false; // call FullName_save() later /* * Set the buffer number to be used for . -- cgit From 189c5abeba4fb508d879ebbf5fa07965c4092cf2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 20 Mar 2018 23:57:41 +0100 Subject: provider/RPC: apply_autocmds_group(): fix double-free During provider dispatch, eval_call_provider() saves global state--including pointers, such as `autocmd_fname`--into `provider_caller_scope` which is later restored by f_rpcrequest(). But `autocmd_fname` is special-cased in eval_vars(), for performance (see Vim patch 7.2.021; this is also the singular purpose of the `autocmd_fname_full` global. Yay!) If eval_vars() frees `autocmd_fname` then its provider-RPC-scoped alias becomes a problem. Solution: Don't free autocmd_fname in eval_vars(), just copy into it. closes #5245 closes #5617 Reference ------------------------------------------------------------------------ Vim patch 7.2.021 https://github.com/vim/vim/commit/f6dad43c98f47da1ff9d8c99b320fc3674f83c63 Problem: When executing autocommands getting the full file name may be slow. (David Kotchan) Solution: Postpone calling FullName_save() until autocmd_fname is used. vim_dev discussion (2008): "Problem with CursorMoved AutoCommand when Editing Files on a Remote WIndows Share" https://groups.google.com/d/msg/vim_dev/kj95weZa_eE/GTgj4aq5sIgJ --- src/nvim/fileio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 91b0a695f1..4e70daea90 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6755,7 +6755,8 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, autocmd_fname = fname_io; } if (autocmd_fname != NULL) { - autocmd_fname = vim_strsave(autocmd_fname); + // Allocate MAXPATHL for when eval_vars() resolves the fullpath. + autocmd_fname = vim_strnsave(autocmd_fname, MAXPATHL); } autocmd_fname_full = false; // call FullName_save() later -- cgit From 82cd0be2eaf71c0476e15c66ba3e83c76896d407 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 11:10:01 +0100 Subject: refactor: eliminate `autocmd_fname_full` global It's a micro-optimization; check path_is_absolute_path(autocmd_fname) instead. The main optimization (which is still in place) afforded by Vim 7.2.021 was to avoid resolving when it is not needed. --- src/nvim/fileio.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 4e70daea90..ea214dd38a 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6655,7 +6655,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, char_u *save_sourcing_name; linenr_T save_sourcing_lnum; char_u *save_autocmd_fname; - int save_autocmd_fname_full; int save_autocmd_bufnr; char_u *save_autocmd_match; int save_autocmd_busy; @@ -6728,7 +6727,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, * Save the autocmd_* variables and info about the current buffer. */ save_autocmd_fname = autocmd_fname; - save_autocmd_fname_full = autocmd_fname_full; save_autocmd_bufnr = autocmd_bufnr; save_autocmd_match = autocmd_match; save_autocmd_busy = autocmd_busy; @@ -6758,7 +6756,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, // Allocate MAXPATHL for when eval_vars() resolves the fullpath. autocmd_fname = vim_strnsave(autocmd_fname, MAXPATHL); } - autocmd_fname_full = false; // call FullName_save() later /* * Set the buffer number to be used for . @@ -6925,7 +6922,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, sourcing_lnum = save_sourcing_lnum; xfree(autocmd_fname); autocmd_fname = save_autocmd_fname; - autocmd_fname_full = save_autocmd_fname_full; autocmd_bufnr = save_autocmd_bufnr; autocmd_match = save_autocmd_match; current_SID = save_current_SID; -- cgit From 998a16c926623a667ecb0228f4a6cd8ba1e90201 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 11:21:20 +0100 Subject: refactor/rename: path_is_absolute() --- src/nvim/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fileio.c') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ea214dd38a..52686f6651 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4318,7 +4318,7 @@ void shorten_fnames(int force) && !path_with_url((char *)buf->b_fname) && (force || buf->b_sfname == NULL - || path_is_absolute_path(buf->b_sfname))) { + || path_is_absolute(buf->b_sfname))) { xfree(buf->b_sfname); buf->b_sfname = NULL; p = path_shorten_fname(buf->b_ffname, dirname); -- cgit