]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.2.0446: runtime(netrw): off-by-one bug in s:NetrwUnMarkFile() v9.2.0446
authorJ. Paulo Seibt <jpseibt@gmail.com>
Tue, 5 May 2026 20:06:15 +0000 (20:06 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 5 May 2026 20:09:58 +0000 (20:09 +0000)
commit7ccc273a4cb6012e5afbdb94d0f2597bc01fe2fd
tree601964ff1185b79b0a0e7631f52768f1cb50883d
parent40fc78f0a185f003844334e7c9dd217d6d993143
patch 9.2.0446: runtime(netrw): off-by-one bug in s:NetrwUnMarkFile()

Problem:  off-by-one bug in s:NetrwUnMarkFile()
Solution: Correctly loop through all buffers to unlet all variables
          (J. Paulo Seibt)

When the function loops through buffers to clear s:netrwmarkfilelist_#
and s:netrwmarkfilemtch_#, it skips the last one at bufnr('$'), messing
up mark highlights and causing other functions that operate on those
arrays (like delete or rename) to target stale marked files.

The bufnr() help page says that bufnr("$") returns the highest buffer
number of existing buffers, so while ibuf < bufnr("$") does not clear
the last buffer-local arrays.

To reproduce:

Just opening a fresh Vim and running :Ex opens a netrw buffer at the
highest number. Then, typing mu after marking some files triggers the
mark highlight bug, and finally typing D would act like calling the
delete function against the previous marked files, as the buffer-local
arrays where not touched by s:NetrwUnMarkFile.

closes: #20129

Signed-off-by: J. Paulo Seibt <jpseibt@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/pack/dist/opt/netrw/autoload/netrw.vim
src/testdir/test_plugin_netrw.vim
src/version.c