mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
No OOM in home_replace_save()
This commit is contained in:
@@ -1908,7 +1908,7 @@ static char_u *fname_match(regprog_T *prog, char_u *name)
|
|||||||
else {
|
else {
|
||||||
/* Replace $(HOME) with '~' and try matching again. */
|
/* Replace $(HOME) with '~' and try matching again. */
|
||||||
p = home_replace_save(NULL, name);
|
p = home_replace_save(NULL, name);
|
||||||
if (p != NULL && vim_regexec(®match, p, (colnr_T)0))
|
if (vim_regexec(®match, p, (colnr_T)0))
|
||||||
match = name;
|
match = name;
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
@@ -18645,17 +18645,13 @@ int store_session_globals(FILE *fd)
|
|||||||
*/
|
*/
|
||||||
void last_set_msg(scid_T scriptID)
|
void last_set_msg(scid_T scriptID)
|
||||||
{
|
{
|
||||||
char_u *p;
|
|
||||||
|
|
||||||
if (scriptID != 0) {
|
if (scriptID != 0) {
|
||||||
p = home_replace_save(NULL, get_scriptname(scriptID));
|
char_u *p = home_replace_save(NULL, get_scriptname(scriptID));
|
||||||
if (p != NULL) {
|
verbose_enter();
|
||||||
verbose_enter();
|
MSG_PUTS(_("\n\tLast set from "));
|
||||||
MSG_PUTS(_("\n\tLast set from "));
|
MSG_PUTS(p);
|
||||||
MSG_PUTS(p);
|
free(p);
|
||||||
free(p);
|
verbose_leave();
|
||||||
verbose_leave();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7909,8 +7909,7 @@ makeopens (
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
} else if (ssop_flags & SSOP_CURDIR) {
|
} else if (ssop_flags & SSOP_CURDIR) {
|
||||||
sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow);
|
sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow);
|
||||||
if (sname == NULL
|
if (fputs("cd ", fd) < 0
|
||||||
|| fputs("cd ", fd) < 0
|
|
||||||
|| ses_put_fname(fd, sname, &ssop_flags) == FAIL
|
|| ses_put_fname(fd, sname, &ssop_flags) == FAIL
|
||||||
|| put_eol(fd) == FAIL) {
|
|| put_eol(fd) == FAIL) {
|
||||||
free(sname);
|
free(sname);
|
||||||
@@ -8535,17 +8534,13 @@ static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp)
|
|||||||
* Write a file name to the session file.
|
* Write a file name to the session file.
|
||||||
* Takes care of the "slash" option in 'sessionoptions' and escapes special
|
* Takes care of the "slash" option in 'sessionoptions' and escapes special
|
||||||
* characters.
|
* characters.
|
||||||
* Returns FAIL if writing fails or out of memory.
|
* Returns FAIL if writing fails.
|
||||||
*/
|
*/
|
||||||
static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
|
static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
|
||||||
{
|
{
|
||||||
char_u *sname;
|
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int retval = OK;
|
|
||||||
|
|
||||||
sname = home_replace_save(NULL, name);
|
char_u *sname = home_replace_save(NULL, name);
|
||||||
if (sname == NULL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
if (*flagp & SSOP_SLASH) {
|
if (*flagp & SSOP_SLASH) {
|
||||||
/* change all backslashes to forward slashes */
|
/* change all backslashes to forward slashes */
|
||||||
@@ -8559,11 +8554,13 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
|
|||||||
free(sname);
|
free(sname);
|
||||||
|
|
||||||
/* write the result */
|
/* write the result */
|
||||||
if (fputs((char *)p, fd) < 0)
|
if (fputs((char *)p, fd) < 0) {
|
||||||
retval = FAIL;
|
free(p);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
return retval;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
@@ -3278,20 +3279,17 @@ home_replace (
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Like home_replace, store the replaced string in allocated memory.
|
* Like home_replace, store the replaced string in allocated memory.
|
||||||
* When something fails, NULL is returned.
|
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u *
|
||||||
home_replace_save (
|
home_replace_save (
|
||||||
buf_T *buf, /* when not NULL, check for help files */
|
buf_T *buf, /* when not NULL, check for help files */
|
||||||
char_u *src /* input file name */
|
char_u *src /* input file name */
|
||||||
)
|
) FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
char_u *dst;
|
|
||||||
|
|
||||||
size_t len = 3; /* space for "~/" and trailing NUL */
|
size_t len = 3; /* space for "~/" and trailing NUL */
|
||||||
if (src != NULL) /* just in case */
|
if (src != NULL) /* just in case */
|
||||||
len += STRLEN(src);
|
len += STRLEN(src);
|
||||||
dst = xmalloc(len);
|
char_u *dst = xmalloc(len);
|
||||||
home_replace(buf, src, dst, (int)len, TRUE);
|
home_replace(buf, src, dst, (int)len, TRUE);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user