From 833a6fcb6095254abae92a2309d7c3ce0e603bf3 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 5 May 2021 21:26:51 -0400 Subject: coverity/331378: Fix inserting new decor provider Since the providers are ordered by ns_id, inserting a new provider may require shifting existing providers around to maintain this ordering. When this happens, we need to allocate a new element at the end of the vector and then shift the larger elements to the right. Rather than iterating (incorrectly) with a loop and copying each item, use memmove to copy the entire block. --- test/functional/ui/decorations_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 09638df6c5..98aafd8757 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -66,6 +66,18 @@ describe('decorations providers', function() expect_events(expected, actual, "beam trace") end + it('does not OOM when inserting, rather than appending, to the decoration provider vector', function() + -- Add a dummy decoration provider with a larger ns id than what setup_provider() creates. + -- This forces get_decor_provider() to insert into the providers vector, + -- rather than append, which used to spin in an infinite loop allocating + -- memory until nvim crashed/was killed. + setup_provider([[ + local ns2 = a.nvim_create_namespace "ns2" + a.nvim_set_decoration_provider(ns2, {}) + ]]) + helpers.assert_alive() + end) + it('leave a trace', function() insert(mulholland) -- cgit