aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml1
-rw-r--r--.github/workflows/release.yml1
-rw-r--r--config/CMakeLists.txt1
-rw-r--r--config/config.h.in1
-rw-r--r--runtime/doc/if_lua.txt8
-rw-r--r--runtime/doc/msgpack_rpc.txt8
-rw-r--r--runtime/filetype.vim3
-rw-r--r--runtime/lua/vim/diagnostic.lua12
-rw-r--r--src/nvim/CMakeLists.txt8
-rw-r--r--src/nvim/api/private/helpers.c2
-rw-r--r--src/nvim/message.c2
-rw-r--r--src/nvim/os/os_defs.h4
-rw-r--r--src/nvim/os/pty_process_unix.c6
-rw-r--r--src/nvim/strings.c12
-rw-r--r--src/nvim/terminal.c7
-rw-r--r--src/nvim/testdir/test_filetype.vim3
-rw-r--r--src/nvim/vim.h5
-rw-r--r--test/functional/terminal/buffer_spec.lua38
-rw-r--r--test/helpers.lua14
19 files changed, 103 insertions, 33 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d07b9fdac7..6a81ee4238 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -67,7 +67,6 @@ jobs:
# Workaround brew issues
rm -f /usr/local/bin/2to3
brew update >/dev/null
- brew upgrade
brew install automake ccache perl cpanminus ninja
- name: Setup interpreter packages
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index f1ed05e6cb..5839be2944 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -82,7 +82,6 @@ jobs:
run: |
rm -f /usr/local/bin/2to3
brew update >/dev/null
- brew upgrade
brew install automake ninja
- if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != 'nightly')
run: printf 'NVIM_BUILD_TYPE=Release\n' >> $GITHUB_ENV
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
index 613475b00d..30f08c5297 100644
--- a/config/CMakeLists.txt
+++ b/config/CMakeLists.txt
@@ -45,6 +45,7 @@ check_function_exists(readlink HAVE_READLINK)
check_function_exists(setpgid HAVE_SETPGID)
check_function_exists(setsid HAVE_SETSID)
check_function_exists(sigaction HAVE_SIGACTION)
+check_function_exists(strnlen HAVE_STRNLEN)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
check_function_exists(strptime HAVE_STRPTIME)
diff --git a/config/config.h.in b/config/config.h.in
index 27a28116af..b0635fb52b 100644
--- a/config/config.h.in
+++ b/config/config.h.in
@@ -30,6 +30,7 @@
#cmakedefine HAVE_SETPGID
#cmakedefine HAVE_SETSID
#cmakedefine HAVE_SIGACTION
+#cmakedefine HAVE_STRNLEN
#cmakedefine HAVE_STRCASECMP
#cmakedefine HAVE_STRINGS_H
#cmakedefine HAVE_STRNCASECMP
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt
deleted file mode 100644
index 34bcf0f039..0000000000
--- a/runtime/doc/if_lua.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- NVIM REFERENCE MANUAL
-
-Moved to |lua.txt|
-
-==============================================================================
- vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt
deleted file mode 100644
index 5368cf0f4f..0000000000
--- a/runtime/doc/msgpack_rpc.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- NVIM REFERENCE MANUAL
-
-This document was merged into |api.txt| and |develop.txt|.
-
-==============================================================================
- vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index e1c917ac64..3e57ae7f0f 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1646,6 +1646,9 @@ au BufNewFile,BufRead .tcshrc,*.tcsh,tcsh.tcshrc,tcsh.login call dist#ft#SetFile
" (patterns ending in a start further below)
au BufNewFile,BufRead .login,.cshrc,csh.cshrc,csh.login,csh.logout,*.csh,.alias call dist#ft#CSH()
+" Zig
+au BufNewFile,BufRead *.zig setf zig
+
" Z-Shell script (patterns ending in a star further below)
au BufNewFile,BufRead .zprofile,*/etc/zprofile,.zfbfmarks setf zsh
au BufNewFile,BufRead .zshrc,.zshenv,.zlogin,.zlogout,.zcompdump setf zsh
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index dfcac33f6d..59cb9f8c5b 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -1344,12 +1344,14 @@ function M.reset(namespace, bufnr)
end
end
- vim.api.nvim_command(
- string.format(
- "doautocmd <nomodeline> DiagnosticChanged %s",
- vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr))
+ vim.api.nvim_buf_call(bufnr, function()
+ vim.api.nvim_command(
+ string.format(
+ "doautocmd <nomodeline> DiagnosticChanged %s",
+ vim.fn.fnameescape(vim.api.nvim_buf_get_name(bufnr))
+ )
)
- )
+ end)
end
--- Add all diagnostics to the quickfix list.
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 185d55daed..bb16459a7f 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -468,9 +468,11 @@ list(APPEND NVIM_LINK_LIBRARIES
if(UNIX)
list(APPEND NVIM_LINK_LIBRARIES
- m
- util
- )
+ m)
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ list(APPEND NVIM_LINK_LIBRARIES
+ util)
+ endif()
endif()
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES} ${LUA_PREFERRED_LIBRARIES})
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index d470def277..9b407eab8b 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -513,7 +513,7 @@ String cbuf_to_string(const char *buf, size_t size)
String cstrn_to_string(const char *str, size_t maxsize)
FUNC_ATTR_NONNULL_ALL
{
- return cbuf_to_string(str, strnlen(str, maxsize));
+ return cbuf_to_string(str, STRNLEN(str, maxsize));
}
/// Creates a String using the given C string. Unlike
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 8a6ac2decc..eaf7e2622a 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -2054,7 +2054,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
msg_ext_last_attr = attr;
}
// Concat pieces with the same highlight
- size_t len = strnlen((char *)str, maxlen); // -V781
+ size_t len = STRNLEN(str, maxlen); // -V781
ga_concat_len(&msg_ext_last_chunk, (char *)str, len);
msg_ext_cur_len += len;
return;
diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h
index 8049b3b80e..dce4b0c187 100644
--- a/src/nvim/os/os_defs.h
+++ b/src/nvim/os/os_defs.h
@@ -13,6 +13,10 @@
# include "nvim/os/unix_defs.h"
#endif
+#if !defined(NAME_MAX) && defined(_XOPEN_NAME_MAX)
+#define NAME_MAX _XOPEN_NAME_MAX
+#endif
+
#define BASENAMELEN (NAME_MAX - 5)
// Use the system path length if it makes sense.
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index 24ecf5c24f..450bc75ffb 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -15,7 +15,7 @@
# include <libutil.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include <util.h>
-#else
+#elif !defined(__sun)
# include <pty.h>
#endif
@@ -198,7 +198,9 @@ static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL
termios->c_cflag = CS8|CREAD;
termios->c_lflag = ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK;
- cfsetspeed(termios, 38400);
+ // not using cfsetspeed, not available on all platforms
+ cfsetispeed(termios, 38400);
+ cfsetospeed(termios, 38400);
#ifdef IUTF8
termios->c_iflag |= IUTF8;
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index c58e052ae9..27f93fe4ce 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -394,6 +394,18 @@ void del_trailing_spaces(char_u *ptr)
}
}
+#if !defined(HAVE_STRNLEN)
+size_t xstrnlen(const char *s, size_t n)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
+{
+ const char *end = memchr(s, '\0', n);
+ if (end == NULL) {
+ return n;
+ }
+ return end - s;
+}
+#endif
+
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP))
/*
* Compare two strings, ignoring case, using current locale.
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index afebda4948..2d32b6bac4 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1507,6 +1507,13 @@ static void refresh_screen(Terminal *term, buf_T *buf)
// Terminal height may have decreased before `invalid_end` reflects it.
term->invalid_end = MIN(term->invalid_end, height);
+ // There are no invalid rows.
+ if (term->invalid_start >= term->invalid_end) {
+ term->invalid_start = INT_MAX;
+ term->invalid_end = -1;
+ return;
+ }
+
for (int r = term->invalid_start, linenr = row_to_linenr(term, r);
r < term->invalid_end; r++, linenr++) {
fetch_row(term, r, width);
diff --git a/src/nvim/testdir/test_filetype.vim b/src/nvim/testdir/test_filetype.vim
index 69edbc227d..31052ce47d 100644
--- a/src/nvim/testdir/test_filetype.vim
+++ b/src/nvim/testdir/test_filetype.vim
@@ -502,7 +502,7 @@ let s:filename_checks = {
\ 'tex': ['file.latex', 'file.sty', 'file.dtx', 'file.ltx', 'file.bbl'],
\ 'texinfo': ['file.texinfo', 'file.texi', 'file.txi'],
\ 'texmf': ['texmf.cnf'],
- \ 'text': ['file.text', 'README', 'LICENSE', 'COPYING', 'AUTHORS', '/usr/share/doc/bash-completion/AUTHORS', '/etc/apt/apt.conf.d/README', '/etc/Muttrc.d/README'],
+ \ 'text': ['file.text', 'file.txt', 'README', 'LICENSE', 'COPYING', 'AUTHORS', '/usr/share/doc/bash-completion/AUTHORS', '/etc/apt/apt.conf.d/README', '/etc/Muttrc.d/README'],
\ 'tf': ['file.tf', '.tfrc', 'tfrc'],
\ 'tidy': ['.tidyrc', 'tidyrc', 'tidy.conf'],
\ 'tilde': ['file.t.html'],
@@ -568,6 +568,7 @@ let s:filename_checks = {
\ 'yaml': ['file.yaml', 'file.yml'],
\ 'raml': ['file.raml'],
\ 'z8a': ['file.z8a'],
+ \ 'zig': ['file.zig'],
\ 'zimbu': ['file.zu'],
\ 'zimbutempl': ['file.zut'],
\ 'zsh': ['.zprofile', '/etc/zprofile', '.zfbfmarks', 'file.zsh', '.zcompdump', '.zlogin', '.zlogout', '.zshenv', '.zshrc', '.zcompdump-file', '.zlog', '.zlog-file', '.zsh', '.zsh-file', 'any/etc/zprofile', 'zlog', 'zlog-file', 'zsh', 'zsh-file'],
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index e3539c1a57..2f8ddd1e88 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -215,6 +215,11 @@ enum { FOLD_TEXT_LEN = 51, }; //!< buffer size for get_foldtext()
// (vim_strchr() is now in strings.c)
#define STRLEN(s) strlen((char *)(s))
+#ifdef HAVE_STRNLEN
+# define STRNLEN(s, n) strnlen((char *)(s), (size_t)(n))
+#else
+# define STRNLEN(s, n) xstrnlen((char *)(s), (size_t)(n))
+#endif
#define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
#define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s), (size_t)(n))
#define STRLCPY(d, s, n) xstrlcpy((char *)(d), (char *)(s), (size_t)(n))
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 7dcca231ee..f25cfa2039 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -6,9 +6,11 @@ local poke_eventloop = helpers.poke_eventloop
local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
local eq, neq = helpers.eq, helpers.neq
local write_file = helpers.write_file
-local command= helpers.command
+local command = helpers.command
local exc_exec = helpers.exc_exec
local matches = helpers.matches
+local exec_lua = helpers.exec_lua
+local sleep = helpers.sleep
describe(':terminal buffer', function()
local screen
@@ -328,3 +330,37 @@ describe('No heap-buffer-overflow when', function()
assert_alive()
end)
end)
+
+describe('on_lines does not emit out-of-bounds line indexes when', function()
+ before_each(function()
+ clear()
+ exec_lua([[
+ function _G.register_callback(bufnr)
+ _G.cb_error = ''
+ vim.api.nvim_buf_attach(bufnr, false, {
+ on_lines = function(_, bufnr, _, firstline, _, _)
+ local status, msg = pcall(vim.api.nvim_buf_get_offset, bufnr, firstline)
+ if not status then
+ _G.cb_error = msg
+ end
+ end
+ })
+ end
+ ]])
+ end)
+
+ it('creating a terminal buffer #16394', function()
+ feed_command([[autocmd TermOpen * ++once call v:lua.register_callback(expand("<abuf>"))]])
+ feed_command('terminal')
+ sleep(500)
+ eq('', exec_lua([[return _G.cb_error]]))
+ end)
+
+ it('deleting a terminal buffer #16394', function()
+ feed_command('terminal')
+ sleep(500)
+ feed_command('lua _G.register_callback(0)')
+ feed_command('bdelete!')
+ eq('', exec_lua([[return _G.cb_error]]))
+ end)
+end)
diff --git a/test/helpers.lua b/test/helpers.lua
index 09b113c01d..87431e4342 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -741,9 +741,20 @@ function module.read_file_list(filename, start)
if not file then
return nil
end
+
+ -- There is no need to read more than the last 2MB of the log file, so seek
+ -- to that.
+ local file_size = file:seek("end")
+ local offset = file_size - 2000000
+ if offset < 0 then
+ offset = 0
+ end
+ file:seek("set", offset)
+
local lines = {}
local i = 1
- for line in file:lines() do
+ local line = file:read("*l")
+ while line ~= nil do
if i >= start then
table.insert(lines, line)
if #lines > maxlines then
@@ -751,6 +762,7 @@ function module.read_file_list(filename, start)
end
end
i = i + 1
+ line = file:read("*l")
end
file:close()
return lines