diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-05-30 21:51:03 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-06-16 01:36:30 -0300 |
commit | f7e64c3c5f70bf642f0ec7bec835f2827939abd7 (patch) | |
tree | 51021294be11305b36e19a39ee14a4d8ceb2b0dc /src | |
parent | d0fe14fdfe0b266a9d8b8da1bc1b12fc49e3c888 (diff) | |
download | rneovim-f7e64c3c5f70bf642f0ec7bec835f2827939abd7.tar.gz rneovim-f7e64c3c5f70bf642f0ec7bec835f2827939abd7.tar.bz2 rneovim-f7e64c3c5f70bf642f0ec7bec835f2827939abd7.zip |
No OOM in vim_strnsave_up()
And some cleanup in strsave_up()
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/strings.c | 20 | ||||
-rw-r--r-- | src/nvim/syntax.c | 12 |
2 files changed, 10 insertions, 22 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 8c82186e15..caf1f444d7 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -13,6 +13,7 @@ #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/mark.h" @@ -214,11 +215,9 @@ char_u *vim_strsave_up(char_u *string) * Like vim_strnsave(), but make all characters uppercase. * This uses ASCII lower-to-upper case translation, language independent. */ -char_u *vim_strnsave_up(char_u *string, int len) +char_u *vim_strnsave_up(char_u *string, int len) FUNC_ATTR_NONNULL_RET { - char_u *p1; - - p1 = vim_strnsave(string, len); + char_u *p1 = vim_strnsave(string, len); vim_strup(p1); return p1; } @@ -251,19 +250,16 @@ char_u *strup_save(char_u *orig) int l; if (enc_utf8) { - int c, uc; - int newl; - char_u *s; - - c = utf_ptr2char(p); - uc = utf_toupper(c); + int c = utf_ptr2char(p); + int uc = utf_toupper(c); /* Reallocate string when byte count changes. This is rare, * thus it's OK to do another malloc()/free(). */ l = utf_ptr2len(p); - newl = utf_char2len(uc); + int newl = utf_char2len(uc); if (newl != l) { - s = xmalloc(STRLEN(res) + 1 + newl - l); + // TODO(philix): use xrealloc() in strup_save() + char_u *s = xmalloc(STRLEN(res) + 1 + newl - l); memmove(s, res, p - res); STRCPY(s + (p - res) + newl, p + l); p = s + (p - res); diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6b4ab867f2..621c6f0d55 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4399,10 +4399,6 @@ syn_cmd_region ( ++key_end; free(key); key = vim_strnsave_up(rest, (int)(key_end - rest)); - if (key == NULL) { /* out of memory */ - rest = NULL; - break; - } if (STRCMP(key, "MATCHGROUP") == 0) item = ITEM_MATCHGROUP; else if (STRCMP(key, "START") == 0) @@ -4692,12 +4688,8 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op) */ static int syn_scl_name2id(char_u *name) { - char_u *name_u; - - /* Avoid using stricmp() too much, it's slow on some systems */ - name_u = vim_strsave_up(name); - if (name_u == NULL) - return 0; + // Avoid using stricmp() too much, it's slow on some systems + char_u *name_u = vim_strsave_up(name); int i; for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; ) { if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL |