diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-02-27 10:38:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-27 10:38:04 +0800 |
commit | 877f3b7288fba61dfc90b1b50c9e4dfa06e32b9a (patch) | |
tree | 02c9536a1a55cf7c664779771ac1c456ef4f90fc | |
parent | 189bba7c770e528f71b5ca129f82d5f7a9e113ea (diff) | |
download | rneovim-877f3b7288fba61dfc90b1b50c9e4dfa06e32b9a.tar.gz rneovim-877f3b7288fba61dfc90b1b50c9e4dfa06e32b9a.tar.bz2 rneovim-877f3b7288fba61dfc90b1b50c9e4dfa06e32b9a.zip |
refactor(shada): fix coverity warning about leaking memory (#32650)
-rw-r--r-- | src/nvim/shada.c | 13 | ||||
-rw-r--r-- | test/functional/shada/shada_spec.lua | 6 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 707c48a495..8496df73ad 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -589,8 +589,7 @@ static int shada_read_file(const char *const file, const int flags) FUNC_ATTR_WARN_UNUSED_RESULT { char *const fname = shada_filename(file); - - if (strequal(fname, "")) { + if (fname == NULL) { return FAIL; } @@ -1283,9 +1282,10 @@ static const char *shada_get_default_file(void) /// /// @param[in] file Forced file name or NULL. /// -/// @return An allocated string containing shada file name. +/// @return An allocated string containing shada file name, +/// or NULL if shada file should not be used. static char *shada_filename(const char *file) - FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT { if (file == NULL || *file == NUL) { if (p_shadafile != NULL && *p_shadafile != NUL) { @@ -1293,7 +1293,7 @@ static char *shada_filename(const char *file) if (!strequal(p_shadafile, "NONE")) { file = p_shadafile; } else { - return ""; + return NULL; } } else { if ((file = find_shada_parameter('n')) == NULL || *file == NUL) { @@ -2696,8 +2696,7 @@ shada_write_exit: int shada_write_file(const char *const file, bool nomerge) { char *const fname = shada_filename(file); - - if (strequal(fname, "")) { + if (fname == NULL) { return FAIL; } diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua index 0d196072e7..651599dc5d 100644 --- a/test/functional/shada/shada_spec.lua +++ b/test/functional/shada/shada_spec.lua @@ -262,6 +262,12 @@ describe('ShaDa support code', function() ) end) + it(':wshada/:rshada without arguments is no-op when shadafile=NONE', function() + nvim_command('set shadafile=NONE') + nvim_command('wshada') + nvim_command('rshada') + end) + it('does not crash when ShaDa file directory is not writable', function() skip(is_os('win')) |