No OOM in vim_strsave_escape_csi()

This commit is contained in:
Felipe Oliveira Carvalho
2014-05-31 00:10:32 -03:00
parent a26a1697c7
commit 3a9a76c996
3 changed files with 9 additions and 16 deletions

View File

@@ -8295,7 +8295,6 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv)
/* Need to escape K_SPECIAL and CSI before putting the string in the /* Need to escape K_SPECIAL and CSI before putting the string in the
* typeahead buffer. */ * typeahead buffer. */
keys_esc = vim_strsave_escape_csi(keys); keys_esc = vim_strsave_escape_csi(keys);
if (keys_esc != NULL) {
ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE), ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE),
typebuf.tb_len, !typed, FALSE); typebuf.tb_len, !typed, FALSE);
free(keys_esc); free(keys_esc);
@@ -8303,7 +8302,6 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv)
typebuf_was_filled = TRUE; typebuf_was_filled = TRUE;
} }
} }
}
/* /*
* "filereadable()" function * "filereadable()" function

View File

@@ -26,6 +26,7 @@
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/farsi.h" #include "nvim/farsi.h"
#include "nvim/func_attr.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
@@ -3760,17 +3761,13 @@ static bool is_user_input(int k)
/* /*
* Copy "p" to allocated memory, escaping K_SPECIAL and CSI so that the result * Copy "p" to allocated memory, escaping K_SPECIAL and CSI so that the result
* can be put in the typeahead buffer. * can be put in the typeahead buffer.
* Returns NULL when out of memory.
*/ */
char_u *vim_strsave_escape_csi(char_u *p) char_u *vim_strsave_escape_csi(char_u *p)
{ {
char_u *res;
char_u *s, *d;
/* Need a buffer to hold up to three times as much. */ /* Need a buffer to hold up to three times as much. */
res = xmalloc(STRLEN(p) * 3 + 1); char_u *res = xmalloc(STRLEN(p) * 3 + 1);
d = res; char_u *d = res;
for (s = p; *s != NUL; ) { for (char_u *s = p; *s != NUL; ) {
if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) {
/* Copy special key unmodified. */ /* Copy special key unmodified. */
*d++ = *s++; *d++ = *s++;

View File

@@ -986,8 +986,6 @@ do_execreg (
return FAIL; return FAIL;
} }
escaped = vim_strsave_escape_csi(y_current->y_array[i]); escaped = vim_strsave_escape_csi(y_current->y_array[i]);
if (escaped == NULL)
return FAIL;
retval = ins_typebuf(escaped, remap, 0, TRUE, silent); retval = ins_typebuf(escaped, remap, 0, TRUE, silent);
free(escaped); free(escaped);
if (retval == FAIL) if (retval == FAIL)