diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-05-30 22:46:26 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-06-16 01:36:31 -0300 |
commit | 8234f2839f78009442b4ed7bc0599e6b581d5cf8 (patch) | |
tree | 58778fbe69bf5d471563a99163e3ade8aa661d32 /src | |
parent | f7e64c3c5f70bf642f0ec7bec835f2827939abd7 (diff) | |
download | rneovim-8234f2839f78009442b4ed7bc0599e6b581d5cf8.tar.gz rneovim-8234f2839f78009442b4ed7bc0599e6b581d5cf8.tar.bz2 rneovim-8234f2839f78009442b4ed7bc0599e6b581d5cf8.zip |
No OOM in vim_strsave_escaped[_ext]()
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/edit.c | 4 | ||||
-rw-r--r-- | src/nvim/eval.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 12 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 22 | ||||
-rw-r--r-- | src/nvim/misc1.c | 10 | ||||
-rw-r--r-- | src/nvim/misc2.c | 2 | ||||
-rw-r--r-- | src/nvim/ops.c | 14 | ||||
-rw-r--r-- | src/nvim/option.c | 6 | ||||
-rw-r--r-- | src/nvim/regexp.c | 6 | ||||
-rw-r--r-- | src/nvim/strings.c | 14 |
10 files changed, 31 insertions, 61 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a802ae4942..7cff8bb9f2 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -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 */ diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 6fcd8b8a26..c2adbc8fbf 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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'; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e39eac993c..d6ad71275b 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f2f00d3bd0..10702775d4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -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 '!'. diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 7e6dec119b..21070b323a 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -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 diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index c064b4c5e6..680dff394f 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -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); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4f1cd5d526..d976b3d4e8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -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(); diff --git a/src/nvim/option.c b/src/nvim/option.c index 5690d2c61f..b610ac463e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -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. */ diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index eab8c58b36..ea61436e05 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -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); diff --git a/src/nvim/strings.c b/src/nvim/strings.c index caf1f444d7..ac0e5e1aef 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -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; |