commit 563a369a1b254851d84c41838a8562ad7e655fa3
parent 734848dc1a9ebdf7af26cf54b92133cc6d94e19c
Author: bfredl <bjorn.linse@gmail.com>
Date: Thu, 21 Mar 2024 17:09:06 +0100
Merge pull request #27961 from bfredl/rpccrash
fix(rpc): do not crash when no input is consumed
Diffstat:
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c
@@ -123,7 +123,10 @@ char *rbuffer_read_ptr(RBuffer *buf, size_t *read_count) FUNC_ATTR_NONNULL_ALL
void rbuffer_consumed(RBuffer *buf, size_t count)
FUNC_ATTR_NONNULL_ALL
{
- assert(count && count <= buf->size);
+ if (count == 0) {
+ return;
+ }
+ assert(count <= buf->size);
buf->read_ptr += count;
if (buf->read_ptr >= buf->end_ptr) {
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
@@ -363,6 +363,24 @@ describe('server -> client', function()
server:close()
client:close()
end)
+
+ it('via stdio, with many small flushes does not crash #23781', function()
+ source([[
+ let chan = jobstart([v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE'], { 'rpc':v:false })
+ call chansend(chan, 0Z94)
+ sleep 50m
+ call chansend(chan, 0Z00)
+ call chansend(chan, 0Z01)
+ call chansend(chan, 0ZAC)
+ call chansend(chan, 0Z6E76696D5F636F6D6D616E64)
+ call chansend(chan, 0Z91)
+ call chansend(chan, 0ZA5)
+ call chansend(chan, 0Z71616C6C21)
+ let g:statuses = jobwait([chan])
+ ]])
+ eq(eval('g:statuses'), { 0 })
+ assert_alive()
+ end)
end)
describe('connecting to its own pipe address', function()