From 8234f2839f78009442b4ed7bc0599e6b581d5cf8 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Fri, 30 May 2014 22:46:26 -0300 Subject: No OOM in vim_strsave_escaped[_ext]() --- src/nvim/strings.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/strings.c') 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; -- cgit