mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00
No OOM in vim_strsave_escaped[_ext]()
This commit is contained in:
@@ -2485,8 +2485,6 @@ ins_compl_dictionaries (
|
||||
if (ctrl_x_mode == CTRL_X_WHOLE_LINE) {
|
||||
char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
|
||||
|
||||
if (pat_esc == NULL)
|
||||
goto theend;
|
||||
size_t len = STRLEN(pat_esc) + 10;
|
||||
ptr = xmalloc(len);
|
||||
vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc);
|
||||
@@ -5253,8 +5251,6 @@ internal_format (
|
||||
*/
|
||||
saved_text = vim_strsave(get_cursor_pos_ptr());
|
||||
curwin->w_cursor.col = orig_col;
|
||||
if (saved_text == NULL)
|
||||
break; /* Can't do it, out of memory */
|
||||
saved_text[startcol] = NUL;
|
||||
|
||||
/* Backspace over characters that will move to the next line */
|
||||
|
@@ -18603,8 +18603,6 @@ int store_session_globals(FILE *fd)
|
||||
* CR into \n and \r. */
|
||||
p = vim_strsave_escaped(get_tv_string(&this_var->di_tv),
|
||||
(char_u *)"\\\"\n\r");
|
||||
if (p == NULL) /* out of memory */
|
||||
break;
|
||||
for (t = p; *t != NUL; ++t)
|
||||
if (*t == '\n')
|
||||
*t = 'n';
|
||||
|
@@ -3545,10 +3545,8 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
|
||||
for (l = repl; *l; ++l)
|
||||
if (vim_strchr(ESCAPE_CHARS, *l) != NULL) {
|
||||
l = vim_strsave_escaped(repl, ESCAPE_CHARS);
|
||||
if (l != NULL) {
|
||||
free(repl);
|
||||
repl = l;
|
||||
}
|
||||
free(repl);
|
||||
repl = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3559,10 +3557,8 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
|
||||
char_u *l;
|
||||
|
||||
l = vim_strsave_escaped(repl, (char_u *)"!");
|
||||
if (l != NULL) {
|
||||
free(repl);
|
||||
repl = l;
|
||||
}
|
||||
free(repl);
|
||||
repl = l;
|
||||
}
|
||||
|
||||
p = repl_cmdline(eap, p, srclen, repl, cmdlinep);
|
||||
|
@@ -2947,17 +2947,13 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
|
||||
/* for ":set path=" we need to escape spaces twice */
|
||||
if (xp->xp_backslash == XP_BS_THREE) {
|
||||
p = vim_strsave_escaped(files[i], (char_u *)" ");
|
||||
if (p != NULL) {
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
#if defined(BACKSLASH_IN_FILENAME)
|
||||
p = vim_strsave_escaped(files[i], (char_u *)" ");
|
||||
if (p != NULL) {
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
}
|
||||
p = vim_strsave_escaped(files[i], (char_u *)" ");
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
p = vim_strsave_fnameescape(files[i], FALSE);
|
||||
@@ -2987,10 +2983,8 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o
|
||||
*/
|
||||
for (i = 0; i < numfiles; ++i) {
|
||||
p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
|
||||
if (p != NULL) {
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
}
|
||||
free(files[i]);
|
||||
files[i] = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3016,7 +3010,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell)
|
||||
p = vim_strsave_escaped(fname, buf);
|
||||
#else
|
||||
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
|
||||
if (shell && csh_like_shell() && p != NULL) {
|
||||
if (shell && csh_like_shell()) {
|
||||
char_u *s;
|
||||
|
||||
/* For csh and similar shells need to put two backslashes before '!'.
|
||||
|
@@ -2847,12 +2847,10 @@ expand_env_esc (
|
||||
if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL) {
|
||||
char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
|
||||
|
||||
if (p != NULL) {
|
||||
if (mustfree)
|
||||
free(var);
|
||||
var = p;
|
||||
mustfree = TRUE;
|
||||
}
|
||||
if (mustfree)
|
||||
free(var);
|
||||
var = p;
|
||||
mustfree = TRUE;
|
||||
}
|
||||
|
||||
if (var != NULL && *var != NUL
|
||||
|
@@ -318,8 +318,6 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
|
||||
|
||||
if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0) {
|
||||
ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', FALSE);
|
||||
if (ecmd == NULL)
|
||||
ecmd = cmd;
|
||||
}
|
||||
ncmd = xmalloc(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1);
|
||||
STRCPY(ncmd, p_sxq);
|
||||
|
@@ -943,14 +943,12 @@ do_execreg (
|
||||
(char_u *)
|
||||
"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037",
|
||||
Ctrl_V, FALSE);
|
||||
if (p != NULL) {
|
||||
/* When in Visual mode "'<,'>" will be prepended to the command.
|
||||
* Remove it when it's already there. */
|
||||
if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0)
|
||||
retval = put_in_typebuf(p + 5, TRUE, TRUE, silent);
|
||||
else
|
||||
retval = put_in_typebuf(p, TRUE, TRUE, silent);
|
||||
}
|
||||
/* When in Visual mode "'<,'>" will be prepended to the command.
|
||||
* Remove it when it's already there. */
|
||||
if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0)
|
||||
retval = put_in_typebuf(p + 5, TRUE, TRUE, silent);
|
||||
else
|
||||
retval = put_in_typebuf(p, TRUE, TRUE, silent);
|
||||
free(p);
|
||||
} else if (regname == '=') {
|
||||
p = get_expr_line();
|
||||
|
@@ -7424,12 +7424,6 @@ int ExpandOldSetting(int *num_file, char_u ***file)
|
||||
* what happens in do_set(). */
|
||||
buf = vim_strsave_escaped(var, escape_chars);
|
||||
|
||||
if (buf == NULL) {
|
||||
free(*file);
|
||||
*file = NULL;
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
/* For MS-Windows et al. we don't double backslashes at the start and
|
||||
* before a file name character. */
|
||||
|
@@ -6500,10 +6500,8 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in
|
||||
if (had_backslash && backslash) {
|
||||
/* Backslashes will be consumed, need to double them. */
|
||||
s = vim_strsave_escaped(eval_result, (char_u *)"\\");
|
||||
if (s != NULL) {
|
||||
free(eval_result);
|
||||
eval_result = s;
|
||||
}
|
||||
free(eval_result);
|
||||
eval_result = s;
|
||||
}
|
||||
|
||||
dst += STRLEN(eval_result);
|
||||
|
@@ -65,6 +65,7 @@ char_u *vim_strnsave(char_u *string, int len) FUNC_ATTR_NONNULL_RET
|
||||
* by a backslash.
|
||||
*/
|
||||
char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars)
|
||||
FUNC_ATTR_NONNULL_RET
|
||||
{
|
||||
return vim_strsave_escaped_ext(string, esc_chars, '\\', FALSE);
|
||||
}
|
||||
@@ -75,10 +76,8 @@ char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars)
|
||||
* Escape the characters with "cc".
|
||||
*/
|
||||
char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int bsl)
|
||||
FUNC_ATTR_NONNULL_RET
|
||||
{
|
||||
char_u *p;
|
||||
char_u *p2;
|
||||
char_u *escaped_string;
|
||||
unsigned length;
|
||||
int l;
|
||||
|
||||
@@ -87,7 +86,7 @@ char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int b
|
||||
* Then allocate the memory and insert them.
|
||||
*/
|
||||
length = 1; /* count the trailing NUL */
|
||||
for (p = string; *p; p++) {
|
||||
for (char_u *p = string; *p; p++) {
|
||||
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
|
||||
length += l; /* count a multibyte char */
|
||||
p += l - 1;
|
||||
@@ -97,9 +96,10 @@ char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int b
|
||||
++length; /* count a backslash */
|
||||
++length; /* count an ordinary char */
|
||||
}
|
||||
escaped_string = xmalloc(length);
|
||||
p2 = escaped_string;
|
||||
for (p = string; *p; p++) {
|
||||
|
||||
char_u *escaped_string = xmalloc(length);
|
||||
char_u *p2 = escaped_string;
|
||||
for (char_u *p = string; *p; p++) {
|
||||
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
|
||||
memmove(p2, p, (size_t)l);
|
||||
p2 += l;
|
||||
|
Reference in New Issue
Block a user