mirror of
https://github.com/neovim/neovim.git
synced 2025-11-25 11:40:40 +00:00
No OOM in vim_strsave_fnameescape()
This commit is contained in:
@@ -8557,8 +8557,6 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
|
|||||||
/* escape special characters */
|
/* escape special characters */
|
||||||
p = vim_strsave_fnameescape(sname, FALSE);
|
p = vim_strsave_fnameescape(sname, FALSE);
|
||||||
free(sname);
|
free(sname);
|
||||||
if (p == NULL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
/* write the result */
|
/* write the result */
|
||||||
if (fputs((char *)p, fd) < 0)
|
if (fputs((char *)p, fd) < 0)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "nvim/ex_eval.h"
|
#include "nvim/ex_eval.h"
|
||||||
#include "nvim/farsi.h"
|
#include "nvim/farsi.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/if_cscope.h"
|
#include "nvim/if_cscope.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
@@ -2960,10 +2961,8 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
|
|||||||
#else
|
#else
|
||||||
p = vim_strsave_fnameescape(files[i], xp->xp_shell);
|
p = vim_strsave_fnameescape(files[i], xp->xp_shell);
|
||||||
#endif
|
#endif
|
||||||
if (p != NULL) {
|
|
||||||
free(files[i]);
|
free(files[i]);
|
||||||
files[i] = p;
|
files[i] = p;
|
||||||
}
|
|
||||||
|
|
||||||
/* If 'str' starts with "\~", replace "~" at start of
|
/* If 'str' starts with "\~", replace "~" at start of
|
||||||
* files[i] with "\~". */
|
* files[i] with "\~". */
|
||||||
@@ -2995,7 +2994,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
|
|||||||
* after a Vim command, or, when "shell" is non-zero, a shell command.
|
* after a Vim command, or, when "shell" is non-zero, a shell command.
|
||||||
* Returns the result in allocated memory.
|
* Returns the result in allocated memory.
|
||||||
*/
|
*/
|
||||||
char_u *vim_strsave_fnameescape(char_u *fname, int shell)
|
char_u *vim_strsave_fnameescape(char_u *fname, int shell) FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
#ifdef BACKSLASH_IN_FILENAME
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
@@ -3011,11 +3010,9 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell)
|
|||||||
#else
|
#else
|
||||||
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
|
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
|
||||||
if (shell && csh_like_shell()) {
|
if (shell && csh_like_shell()) {
|
||||||
char_u *s;
|
|
||||||
|
|
||||||
/* For csh and similar shells need to put two backslashes before '!'.
|
/* For csh and similar shells need to put two backslashes before '!'.
|
||||||
* One is taken by Vim, one by the shell. */
|
* One is taken by Vim, one by the shell. */
|
||||||
s = vim_strsave_escaped(p, (char_u *)"!");
|
char_u *s = vim_strsave_escaped(p, (char_u *)"!");
|
||||||
free(p);
|
free(p);
|
||||||
p = s;
|
p = s;
|
||||||
}
|
}
|
||||||
@@ -3023,8 +3020,9 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell)
|
|||||||
|
|
||||||
/* '>' and '+' are special at the start of some commands, e.g. ":edit" and
|
/* '>' and '+' are special at the start of some commands, e.g. ":edit" and
|
||||||
* ":write". "cd -" has a special meaning. */
|
* ":write". "cd -" has a special meaning. */
|
||||||
if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL)))
|
if (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL)) {
|
||||||
escape_fname(&p);
|
escape_fname(&p);
|
||||||
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user