fix(sign): avoid deleting from sign map while looping over it (#27158)

This commit is contained in:
luukvbaal 2024-01-23 22:51:18 +01:00 committed by GitHub
parent 932c7eb019
commit fcd9905291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -1021,9 +1021,14 @@ static void sign_get_placed(buf_T *buf, linenr_T lnum, int id, const char *group
void free_signs(void)
{
cstr_t name;
kvec_t(cstr_t) names = KV_INITIAL_VALUE;
map_foreach_key(&sign_map, name, {
sign_undefine_by_name(name);
kv_push(names, name);
});
for (size_t i = 0; i < kv_size(names); i++) {
sign_undefine_by_name(kv_A(names, i));
}
kv_destroy(names);
}
static enum {

View File

@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, feed, exec, api = helpers.clear, helpers.feed, helpers.exec, helpers.api
local api, clear, eq = helpers.api, helpers.clear, helpers.eq
local eval, exec, feed = helpers.eval, helpers.exec, helpers.feed
describe('Signs', function()
local screen
@ -565,4 +566,13 @@ describe('Signs', function()
|
]])
end)
it('sign_undefine() frees all signs', function()
exec([[
sign define 1 text=1
sign define 2 text=2
call sign_undefine()
]])
eq({}, eval('sign_getdefined()'))
end)
end)