diff options
author | erw7 <erw7.github@gmail.com> | 2020-07-31 23:08:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-31 16:08:34 +0200 |
commit | a4fe8bdc97c9313eb4543427cde75c54f7be8895 (patch) | |
tree | a9616595d5b7a290ac9ced87aaf2a648b0619750 | |
parent | 82bfdbfe5c4eebd98ef59b52045ffd198e7ff389 (diff) | |
download | rneovim-a4fe8bdc97c9313eb4543427cde75c54f7be8895.tar.gz rneovim-a4fe8bdc97c9313eb4543427cde75c54f7be8895.tar.bz2 rneovim-a4fe8bdc97c9313eb4543427cde75c54f7be8895.zip |
shada: fix failed assertion on exit (#12692)
If set the number of history saves is 0, assertions fail when inserting an entry on exit.
Dont insert an entry when the number of saves is 0 fixes the issue.
fixes #11497
-rw-r--r-- | src/nvim/shada.c | 8 | ||||
-rw-r--r-- | test/functional/shada/history_spec.lua | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 95257fe945..aa19d1db1f 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2207,8 +2207,12 @@ static inline ShaDaWriteResult shada_read_when_writing( shada_free_shada_entry(&entry); break; } - hms_insert(&wms->hms[entry.data.history_item.histtype], entry, true, - true); + if (wms->hms[entry.data.history_item.histtype].hmll.size != 0) { + hms_insert(&wms->hms[entry.data.history_item.histtype], entry, true, + true); + } else { + shada_free_shada_entry(&entry); + } break; } case kSDItemRegister: { diff --git a/test/functional/shada/history_spec.lua b/test/functional/shada/history_spec.lua index 78b5c77857..9291f5e100 100644 --- a/test/functional/shada/history_spec.lua +++ b/test/functional/shada/history_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local nvim_command, funcs, meths, nvim_feed, eq = helpers.command, helpers.funcs, helpers.meths, helpers.feed, helpers.eq +local eval = helpers.eval local shada_helpers = require('test.functional.shada.helpers') local reset, clear = shada_helpers.reset, shada_helpers.clear @@ -237,4 +238,13 @@ describe('ShaDa support code', function() nvim_command('wshada') end) + it('does not crash when number of history save to zero (#11497)', function() + nvim_command('set shada=\'10') + nvim_feed(':" Test\n') + nvim_command('wshada') + nvim_command('set shada=\'10,:0') + nvim_command('wshada') + eq(2, eval('1+1')) -- check nvim still running + end) + end) |