mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
refactor(shada): fix coverity warning about leaking memory (#32650)
This commit is contained in:
@@ -589,8 +589,7 @@ static int shada_read_file(const char *const file, const int flags)
|
|||||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
char *const fname = shada_filename(file);
|
char *const fname = shada_filename(file);
|
||||||
|
if (fname == NULL) {
|
||||||
if (strequal(fname, "")) {
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1283,9 +1282,10 @@ static const char *shada_get_default_file(void)
|
|||||||
///
|
///
|
||||||
/// @param[in] file Forced file name or NULL.
|
/// @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)
|
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 (file == NULL || *file == NUL) {
|
||||||
if (p_shadafile != NULL && *p_shadafile != NUL) {
|
if (p_shadafile != NULL && *p_shadafile != NUL) {
|
||||||
@@ -1293,7 +1293,7 @@ static char *shada_filename(const char *file)
|
|||||||
if (!strequal(p_shadafile, "NONE")) {
|
if (!strequal(p_shadafile, "NONE")) {
|
||||||
file = p_shadafile;
|
file = p_shadafile;
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((file = find_shada_parameter('n')) == NULL || *file == NUL) {
|
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)
|
int shada_write_file(const char *const file, bool nomerge)
|
||||||
{
|
{
|
||||||
char *const fname = shada_filename(file);
|
char *const fname = shada_filename(file);
|
||||||
|
if (fname == NULL) {
|
||||||
if (strequal(fname, "")) {
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -262,6 +262,12 @@ describe('ShaDa support code', function()
|
|||||||
)
|
)
|
||||||
end)
|
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()
|
it('does not crash when ShaDa file directory is not writable', function()
|
||||||
skip(is_os('win'))
|
skip(is_os('win'))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user