Problem: Undefined behavior when 'undodir' contains empty entry.
Solution: Don't try to remove trailing slashes from empty path. Also
don't remove a colon on Windows while at it.
Fixes the following Coverity warning:
*** CID 549779: Integer handling issues (INTEGER_OVERFLOW)
/src/nvim/undo.c: 717 in u_get_undo_file_name()
711 dir_name[dir_len] = NUL;
712
713 // Remove trailing pathseps from directory name
714 char *p = &dir_name[dir_len - 1];
715 while (vim_ispathsep(*p)) {
716 *p-- = NUL;
>>> CID 549779: Integer handling issues (INTEGER_OVERFLOW)
>>> Expression "dir_len--", where "dir_len" is known to be equal to 0, underflows the type of "dir_len--", which is type "size_t".
717 dir_len--;
718 }
719
720 bool has_directory = os_isdir(dir_name);
721 if (!has_directory && *dirp == NUL && !reading) {
722 // Last directory in the list does not exist, create it.
Problem: 'inccommand' preview is not executed after setcmdline(),
and as a result cmdline_show event is emitted when redrawing
is not allowed (5b6477be).
Solution: Call command_line_changed() when ccline.cmdbuff_replaced is
set (by setcmdline()).
Problem:
We normally get the background color via continuous reporting. However,
if we were backgrounded while the light/dark mode changed, we won't have
received the report, and we'll have the wrong background color.
Without this change, if you background nvim, toggle the light/dark mode,
resume, and check `:set bg`, it will not match the current state.
Solution:
Query it on resume as well. (This requires separating the query from the
flush, to just do the query along with all the others, while waiting to
flush until we've set up uv.)
With this change, if you background nvim, toggle the light/dark mode,
resume, and check `:set bg`, it will have updated.
Problem: vim.ui_attach() msg_show callback runs the risk of a recursive
loop_uv_run() when trying to display a message from a shell
command stream.
Solution: Schedule the message callback on the fast_events queue.
Problem: Normal Windows builtin-TUI startup spawns the embedded server as DETACHED_PROCESS, which breaks Ctrl-C delivery to :terminal jobs.
Solution: Restores the default behavior once the embedded server has a
console so terminal jobs inherit it.
Problem: :packadd may lead to heap-buffer-overflow when all entries in
'runtimepath' have the same length (after 9.2.0291).
Solution: Check for comma after current entry properly (zeertzjq).
related: vim/vim#19854
closes: vim/vim#19911bc182ae56e
Problem: too many strlen() calls
Solution: refactor concat_fname() and remove calls to strlen()
(John Marriott)
Function `concat_fnames()` can make up to 5 calls to `STRLEN()` (either
directly or indirectly via `STRCAT()`). In many cases the lengths of
arguments `fname1` and/or `fname2` are either known or can simply be
calculated.
This Commit refactors this function to accept the lengths of arguments
`fname1` and `fname2` as arguments. It also adds new argument `ret` to
return the resulting string as a `string_T`.
Additionally:
- function `add_pack_dir_to_rtp()` in `scriptfile.c`:
Use a `string_T` to store local variables `new_rtp` and `afterdir`.
Replace calls to `STRCAT()` with calls to `STRCPY()`.
Change type of variable `keep` to `size_t` for consistency with
other lengths.
- function `qf_get_fnum()` in `quickfix.c`:
Use a `string_T` to store local variables `ptr` and `bufname`
- function `qf_push_dir()` in `quickfix.c`:
Use a `string_T` to store local variable `dirname`.
Replace call to `vim_strsave()` with `vim_strnsave()`.
- function `qf_guess_filepath()` in `quickfix.c`:
Use a `string_T` to store local variable `fullname`.
- function `make_percent_swname()` in `memline.c`:
Rename some variables to better reflect their use.
Use a `string_T` to store local variables `d` and `fixed_name`.
Slightly refactor to remove need to create an extra string.
- function `get_file_in_dir()` in `memline.c`:
Use a `string_T` to store local variables `tail` and `retval`.
Move some variables closer to where they are used.
- function `cs_resolve_file()` in `if_cscope.c`:
Use a `string_T` to store local variable `csdir`.
Remove one call to `STRLEN()`.
- function `add_pathsep()` in `filepath.c`:
Refactor and remove 1 call to `STRLEN()`
- function `set_init_xdg_rtp()` in `option.c`:
Use a `string_T` to store local variable `vimrc_xdg`.
closes: vim/vim#19854cb51add7ae
Co-authored-by: John Marriott <basilisk@internode.on.net>
Co-authored-by: Christian Brabandt <cb@256bit.org>
Problem:
On Windows, `:!echo тест` shows `????` because the console code page defaults to a legacy ANSI encoding (e.g. CP1252) instead of `UTF-8`
Solution:
Call `SetConsoleOutputCP(CP_UTF8)` and `SetConsoleCP(CP_UTF8)` in `do_os_system()` before spawning child processes, and restore the original values after. It covers both `:!` and `system()` since they both go through `do_os_system()`
vim-patch:9.2.0286: still some unnecessary (int) casts in alloc()
vim-patch:9.2.0288: libvterm: signed integer overflow parsing long CSI args
vim-patch:bd8b6c6b0 CI: Bump codecov/codecov-action
vim-patch:9.2.0294: if_lua: lua interface does not work with lua 5.5
vim-patch:9.2.0297: libvterm: can improve CSI overflow code
vim-patch:8.2.0356: MS-Windows: feedkeys() with VIMDLL cannot handle CSI
vim-patch:8.2.0647: MS-Windows: repeat count for events was not used
Problem: Crash on exit after closing v:stderr channel when piping
to stdin.
Solution: Reopen stderr as /dev/null or NUL instead of closing it.
This also avoids writing to an related file if one is opened
after closing v:stderr.
Problem: Some internal variables are not modified
Solution: Add const qualifier to static table data
(Hirohito Higashi).
Several static arrays that are never modified at runtime were missing the
const qualifier. Add const to move them from .data to .rodata section.
closes: vim/vim#199013c79e33aeb
Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Problem: Currently `colnr_T` and `int` and the same type, so casting
`int *` to `colnr_T *` is redundant. Additionally, even if
they are changed to different types in the future, these casts
are incorrect as they won't work on big-endian platforms.
Solution: Remove the casts. Also fix two cases of passing false instead
of 0 to an integer argument (zeertzjq).
related: vim/vim#19672
closes: vim/vim#1990718cd55dbc4
Problem: 'showcmd' shows wrong Visual block size with 'linebreak' after
end char (after 7.4.467).
Solution: Exclude 'linebreak' from end position. Also fix confusing test
function names.
closes: vim/vim#1990808bd9114c1
Problem: 'linebreak' may lead to wrong Visual block highlighting when
end char occupies multiple cells (after 7.4.467).
Solution: Exclude 'linebreak' from the ending column instead of setting
'virtualedit' temporarily (zeertzjq).
fixes: vim/vim#19898closes: vim/vim#1990023be1889d1
- Don't go over 78 columns.
- Change the first "and" to "or", as "or" is used below.
- Change "takes one" to "switches", as "one" may be mistaken as
referring to the command instead of the user.
- Use backticks in :h 'autowriteall' like in :h 'autowrite'.
closes: vim/vim#19859af58a9f5e9
vim-patch:f4f175332 translation(ru): updated the Russian man page the xxd
vim-patch:e4502b603 translation(ru): updated lang/README.ru.txt
vim-patch:2c976d0de SECURITY.md: clarify the use of AI
vim-patch:9.2.0279: terminal: out-of-bounds write with overlong CSI argument list
vim-patch:9d83ca5ca runtime(preproc_indent): Ignore Swapfiles when loading buffers
Co-authored-by: marvim <marvim@users.noreply.github.com>
Problem: :syn sync grouphere may go beyond end of line.
Solution: Start searching for the end of region at the end of match
instead of a possibly invalid position (zeertzjq).
closes: vim/vim#19896b7cffc8434
This PR creates a C function `nts_parser_parse_buf()`
which is like `ts_parser_parse_string()` but instead can be passed
an nvim buffer number to parse.
Refactor #37977: instead of allocating a hidden console at startup, borrow the parent's console via AttachConsole() and only create an isolated hidden console when :detach is called, with fd 0/1/2 re-bound to the new CONIN$/CONOUT$.
Problem: tests: test_modeline.vim fails (after v9.2.0276)
Solution: Rewrite the tests to use the existing s:modeline_fails()
function, update documentation (zeertzjq).
8c8772c6b3
Problem: When 'ruler' is in last line of the screen and the current
floating window is closed, the ruler is not cleared.
Solution: When closing the current floating window, redraw the cmdline
if that contained, and will no longer contain the 'ruler'.
Problem: Cmdline is not redrawn after an empty message clears it.
Remembered last drawn cursor position may be outdated but
equal to the current cmdline content with UI2.
Solution: Ensure cmdline is redrawn after an empty message clears it.
Compare wanted cursor position with actual cursor position.
Problem: fileinfo not shown after :bd of last listed buffer
(memeplex)
Solution: Set need_fileinfo to true in empty_curbuf()
(Hirohito Higashi)
When deleting the last listed buffer with :bd, the new empty buffer's
file info (e.g. "[No Name]" --No lines in buffer--) was not displayed.
do_ecmd() only calls fileinfo() for existing buffers (oldbuf), not for
newly created empty buffers.
Set need_fileinfo in empty_curbuf() so the file info is displayed after
redraw.
fixes: vim/vim#548closes: vim/vim#198023d472d8675
Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Let's add the --no-location to the xgettext command line call, so that
the generated vim.pot file does not contain the message location. Those
will get out of date soon and we don't want to update vim.pot just
because the location in a comment changes.
2844765e90
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Co-authored-by: Christian Brabandt <cb@256bit.org>
vim-patch:9.1.0333: tests: test_xdg fails on the appimage repo
vim-patch:9.1.0336: tests: typo in test_xdg
vim-patch:9.1.0339: tests: xdg test uses screen dumps
vim-patch:9.1.0347: A few typos in test_xdg when testing gvimrc
vim-patch:b9897ec27 runtime(xdg): remove // from 'undo' and 'viwedir'
vim-patch:2e9e7cb8e runtime(xdg): Move viminfofile storage to state dir
vim-patch:9.2.0255: tests: Test_popup_opacity_vsplit() fails in a wide terminal
vim-patch:9.2.0260: statusline not redrawn after closing a popup window
vim-patch:9.2.0261: terminal: redraws are slow
vim-patch:9.2.0264: Cannot disable kitty keyboard protocol in vim :terminal
vim-patch:9.2.0268: memory leak in call_oc_method()
vim-patch:9.2.0269: configure: Link error on Solaris
vim-patch:9.2.0258: memory leak in add_mark()
The NULL checks added in #35679 are no longer needed after #38473.
_____________________________________________________________________________________________
*** CID 645258: (REVERSE_INULL)
/src/nvim/buffer.c: 645 in close_buffer()
639 // Autocommands deleted the buffer.
640 emsg(_(e_auabort));
641 return false;
642 }
643 buf->b_locked--;
644 buf->b_locked_split--;
>>> CID 645258: (REVERSE_INULL)
>>> Null-checking "win" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
645 if (abort_if_last && win != NULL && one_window(win, NULL)) {
646 // Autocommands made this the only window.
647 emsg(_(e_auabort));
648 return false;
649 }
650 }
/src/nvim/buffer.c: 626 in close_buffer()
620 // Autocommands deleted the buffer.
621 emsg(_(e_auabort));
622 return false;
623 }
624 buf->b_locked--;
625 buf->b_locked_split--;
>>> CID 645258: (REVERSE_INULL)
>>> Null-checking "win" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
626 if (abort_if_last && win != NULL && one_window(win, NULL)) {
627 // Autocommands made this the only window.
628 emsg(_(e_auabort));
629 return false;
630 }
631
Problem:
Since neovim 0.12, shift + arrow keys no longer works in rxvt-unicode
(TERM=rxvt-unicode-256color).
Solution:
Re-add `left` and `right` to `wanted_termkeys` so they're read from
terminfo instead of being handled by driver-csi. There seems to be quite
a few other terminals that define kLFT in terminfo.src and these are
likely to be affected as well.
Fixes: https://github.com/neovim/neovim/issues/38571
Fixes: 4b678a499c ("refactor(termkey): make termkey use internal terminfo properly")
Problem:
`gen_terminfo.lua`'s output is unpredictable and depends on the system
ncurses version.
Invoking `tic` on `scripts/windows.ti` alone makes it use the system
terminfo definitions for the `use=…` fragments in `windows.ti` such as:
use=xterm+256color, use=xterm+sl, use=xterm-new
This is particularly problematic on Debian, as they build ncurses with
`--with-xterm-kbs=del` [1], and thus some of the windows entries end up
with different definitions for `kTermKey_left`, which is almost
certainly not desired.
[1]: 2d238cf387/debian/rules (L149)
Solution:
This reverts commit 9f90992934.
Problem: buffer underflow in vim_fgets()
Solution: Ensure size is always greater than 1
(Koda Reef)
3c0f8000e1
This currently never happens in Nvim.
Co-authored-by: Koda Reef <kodareef5@gmail.com>
Problem: w_locked can be bypassed when recursively set if not restored
to its prior value.
Solution: Rather than save/restore everywhere, just make it a count,
like other locks (Sean Dewar)
Requires the previous commit, otherwise b_nwindows will be wrong in
tests, which causes a bunch of weird failures.
closes: vim/vim#197287cb43f286e
Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Problem: close_buffer() callers incorrectly handle b_nwindows,
especially after nasty autocmds, allowing it to go
out-of-sync. May lead to buffers that can't be unloaded, or
buffers that are prematurely freed whilst displayed.
Solution: Modify close_buffer() and review its callers; let them
decrement b_nwindows if it didn't unload the buffer. Remove
some now unneeded workarounds like 8.2.2354, 9.1.0143,
9.1.0764, which didn't always work (Sean Dewar)
(endless yapping omitted)
related: vim/vim#19728bf21df1c7b
b_nwindows = 0 change for free_all_mem() was already ported.
Originally Nvim returned true when b_nwindows was decremented before the end was
reached (to better indicate the decrement). That's not needed anymore, so just
return true only at the end, like Vim. (retval isn't used anywhere now anyways)
Set textlock for dict watchers at the end of close_buffer() to prevent them from
switching windows, as that can leave a window with a NULL buffer. (possible
before this PR, but the new assert catches it; added a test)
Despite textlock, things still aren't ideal, as watchers may observe the buffer
as unloaded and hidden (b_nwindows was decremented), yet still in a window...
Likewise, for Nvim, wipe_qf_buffer()'s comment may not be entirely accurate;
autocmds are blocked, but on_detach callbacks (textlocked) and dict watchers may
still run. Might be problematic, but those aren't new issues.
Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>