No OOM in vim_strsave_fnameescape()

This commit is contained in:
Felipe Oliveira Carvalho
2014-05-30 23:51:39 -03:00
parent 81ca5ff126
commit cca66742eb
2 changed files with 7 additions and 11 deletions

View File

@@ -28,6 +28,7 @@
#include "nvim/ex_eval.h"
#include "nvim/farsi.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/if_cscope.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
p = vim_strsave_fnameescape(files[i], xp->xp_shell);
#endif
if (p != NULL) {
free(files[i]);
files[i] = p;
}
free(files[i]);
files[i] = p;
/* If 'str' starts with "\~", replace "~" at start of
* 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.
* 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;
#ifdef BACKSLASH_IN_FILENAME
@@ -3011,11 +3010,9 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell)
#else
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
if (shell && csh_like_shell()) {
char_u *s;
/* For csh and similar shells need to put two backslashes before '!'.
* 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);
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
* ":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);
}
return p;
}