From eecc4b73ffe614a5fa79992d4890c234c0fe2f0f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 7 Aug 2026 22:40:32 +0200 Subject: [PATCH 1/2] fix(coverity): UNINIT, FORWARD_NULL CID 652778: Uninitialized variables (UNINIT) /src/nvim/context.c: 353 in ctx_dirs_save() 347 if (curbuf->b_sfname != NULL && curbuf->b_fname == curbuf->b_sfname) { 348 cs->cs_save_sfname = xstrdup(curbuf->b_sfname); 349 } 350 do_autochdir(); 351 char autocwd[MAXPATHL]; 352 if (os_dirname(autocwd, MAXPATHL) == OK) { >>> CID 652778: Uninitialized variables (UNINIT) >>> Using uninitialized value "*cwd" when calling "strcmp". 353 cs->cs_apply_acd = strcmp(cwd, autocwd) == 0; 354 } 355 } 356 } 357 358 /// Restores the dir state saved by ctx_dirs_save(), undoing any chdir made while switched. The CID 652777: Null pointer dereferences (FORWARD_NULL) /src/nvim/context.c: 556 in ctx_switch() 550 cs->cs_target_win = wp->handle; 551 cs->cs_target_old_pos = wp->w_cursor; 552 } 553 // The CWD-state snapshot is only for a real window target; hidden-buffer target is handled by the 554 // ctx_win machinery (ctx_win_prep). 555 if (buf == NULL || wp != NULL) { >>> CID 652777: Null pointer dereferences (FORWARD_NULL) >>> Passing null pointer "wp" to "ctx_dirs_save", which dereferences it. 556 ctx_dirs_save(cs, wp, tp == NULL ? curtab : tp, buf); 557 } 558 559 // Save the current state. 560 cs->cs_curwin = curwin->handle; 561 cs->cs_prevwin = prevwin == NULL ? 0 : prevwin->handle; --- src/nvim/context.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nvim/context.c b/src/nvim/context.c index 24855b5a3b..6575f79000 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -312,6 +312,7 @@ static void ctx_localdirs_restore(CtxSwitch *cs, win_T *cwp, tabpage_T *tp, bool /// ('autochdir', win/tab-local directories) can be undone. /// - kCtxKeepDirs: also copies of the target context's dir scopes (w/b/tp-local, global). static void ctx_dirs_save(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf) + FUNC_ATTR_NONNULL_ARG(1, 2, 3) { if (!(cs->cs_flags & (kCtxKeepCwd | kCtxKeepDirs))) { return; @@ -332,8 +333,8 @@ static void ctx_dirs_save(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf) char cwd[MAXPATHL]; if ((cs->cs_flags & kCtxKeepDirs) || (curwin != wp - && (curwin->w_localdir != NULL || (wp != NULL && wp->w_localdir != NULL) - || curbuf->b_localdir != NULL || (wp != NULL && wp->w_buffer->b_localdir != NULL) + && (curwin->w_localdir != NULL || wp->w_localdir != NULL + || curbuf->b_localdir != NULL || wp->w_buffer->b_localdir != NULL || (curtab != tp && (curtab->tp_localdir != NULL || tp->tp_localdir != NULL)) || p_acd))) { if (os_dirname(cwd, MAXPATHL) == OK) { @@ -350,7 +351,7 @@ static void ctx_dirs_save(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf) do_autochdir(); char autocwd[MAXPATHL]; if (os_dirname(autocwd, MAXPATHL) == OK) { - cs->cs_apply_acd = strcmp(cwd, autocwd) == 0; + cs->cs_apply_acd = strcmp(cs->cs_cwd, autocwd) == 0; } } } @@ -552,7 +553,7 @@ bool ctx_switch(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf, CtxSwitchFl } // The CWD-state snapshot is only for a real window target; hidden-buffer target is handled by the // ctx_win machinery (ctx_win_prep). - if (buf == NULL || wp != NULL) { + if (wp != NULL) { ctx_dirs_save(cs, wp, tp == NULL ? curtab : tp, buf); } From 9e283f273b2bece25c1602fb4d26b1dff76ec105 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 7 Aug 2026 22:38:32 +0200 Subject: [PATCH 2/2] test(terminal): unreliable "spawns in CWD effective at time of invocation" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FAILED …/terminal/ex_terminal_spec.lua @ 270: :terminal (fake shell) spawns in CWD effective at time of invocation Expected values to differ. Value: "~/work/neovim/neovim/build/Xtest_xdg_terminal" stack traceback: …/terminal/ex_terminal_spec.lua:276: in function <…/terminal/ex_terminal_spec.lua:270> --- test/functional/terminal/ex_terminal_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 95e2079aef..c9f8fc8859 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -268,13 +268,13 @@ local function test_terminal_with_fake_shell(backslash) end) it('spawns in CWD effective at time of invocation', function() - command('terminal') + -- Run "echo" so the default TermClose handler does not auto-delete an exitcode=0 shell. + command('terminal echo') local dir = fn.bufname():match('^term://(.-)//') - command('bcd ..') -- :terminal should use this CWD. - command('terminal') - local parent = fn.bufname():match('^term://(.-)//') - neq(dir, parent) - eq(fn.fnamemodify(dir, ':h'), parent) + local parentdir = fn.fnamemodify(fn.getcwd(), ':h') -- Absolute, so 'cdpath' cannot interfere. + command(('bcd %s'):format(fn.fnameescape(parentdir))) -- :terminal should use this CWD. + command('terminal echo') + eq(fn.fnamemodify(dir, ':h'), fn.bufname():match('^term://(.-)//')) end) it('allows quotes and slashes', function()