Skip to content

Commit 563a369

Browse files
authored
Merge pull request neovim#27961 from bfredl/rpccrash
fix(rpc): do not crash when no input is consumed
2 parents 734848d + 8921d56 commit 563a369

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: src/nvim/rbuffer.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ char *rbuffer_read_ptr(RBuffer *buf, size_t *read_count) FUNC_ATTR_NONNULL_ALL
123123
void rbuffer_consumed(RBuffer *buf, size_t count)
124124
FUNC_ATTR_NONNULL_ALL
125125
{
126-
assert(count && count <= buf->size);
126+
if (count == 0) {
127+
return;
128+
}
129+
assert(count <= buf->size);
127130

128131
buf->read_ptr += count;
129132
if (buf->read_ptr >= buf->end_ptr) {

Diff for: test/functional/api/server_requests_spec.lua

+18
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ describe('server -> client', function()
363363
server:close()
364364
client:close()
365365
end)
366+
367+
it('via stdio, with many small flushes does not crash #23781', function()
368+
source([[
369+
let chan = jobstart([v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE'], { 'rpc':v:false })
370+
call chansend(chan, 0Z94)
371+
sleep 50m
372+
call chansend(chan, 0Z00)
373+
call chansend(chan, 0Z01)
374+
call chansend(chan, 0ZAC)
375+
call chansend(chan, 0Z6E76696D5F636F6D6D616E64)
376+
call chansend(chan, 0Z91)
377+
call chansend(chan, 0ZA5)
378+
call chansend(chan, 0Z71616C6C21)
379+
let g:statuses = jobwait([chan])
380+
]])
381+
eq(eval('g:statuses'), { 0 })
382+
assert_alive()
383+
end)
366384
end)
367385

368386
describe('connecting to its own pipe address', function()

0 commit comments

Comments
 (0)