fix(startup): crash in read_stdin #35699

Problem:
Crash on startup in some situations due to call to `set_curbuf`
with the current value of `cur_buf`.

Solution:
Switch buffers before doing the wipeout of the stdin buffer.
Use cmdline cmds instead of raw buffer pointers to avoid lifetime issues.
This commit is contained in:
Cameron Ring
2025-09-10 21:37:42 -07:00
committed by GitHub
parent 2e70f3522b
commit 0f64f0f5b6
2 changed files with 52 additions and 18 deletions

View File

@@ -536,7 +536,7 @@ describe('startup', function()
it('if stdin is empty and - is last: selects buffer 1, deletes buffer 3 #35269', function()
eq(
'\r\n 1 %a "file1" line 0\r\n 2 #h "file2" line 1',
'\r\n 1 %a "file1" line 0\r\n 2 "file2" line 0',
fn.system({
nvim_prog,
'-n',
@@ -554,6 +554,30 @@ describe('startup', function()
)
end)
it("empty stdin with terminal split doesn't crash #35681", function()
eq(
'nocrash',
fn.system({
nvim_prog,
'-n',
'-u',
'NONE',
'-i',
'NONE',
'--headless',
'--cmd',
'term',
'+split',
'+quit!',
'+bw!',
'+bw!',
'+echo "nocrash"',
"+call timer_start(1, { -> execute('qa') })", -- need to let event handling happen
'-',
}, { '' })
)
end)
it('stdin with -es/-Es #7679', function()
local input = { 'append', 'line1', 'line2', '.', '%print', '' }
local inputstr = table.concat(input, '\n')