From a80d7e86c1f088c5b68d8e8929cc72a0d9680f76 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Thu, 8 May 2014 21:34:46 -0300 Subject: Remove NULL/non-NULL tests after calls to vim_str(n)save() --- src/nvim/getchar.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index efa63f2682..440349ff1b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2636,7 +2636,6 @@ do_map ( char_u *p; int n; int len = 0; /* init for GCC */ - char_u *newstr; int hasarg; int haskey; int did_it = FALSE; @@ -2979,13 +2978,8 @@ do_map ( } else { /* new rhs for existing entry */ mp->m_mode &= ~mode; /* remove mode bits */ if (mp->m_mode == 0 && !did_it) { /* reuse entry */ - newstr = vim_strsave(rhs); - if (newstr == NULL) { - retval = 4; /* no mem */ - goto theend; - } free(mp->m_str); - mp->m_str = newstr; + mp->m_str = vim_strsave(rhs); free(mp->m_orig_str); mp->m_orig_str = vim_strsave(orig_rhs); mp->m_noremap = noremap; @@ -3057,14 +3051,6 @@ do_map ( mp->m_keys = vim_strsave(keys); mp->m_str = vim_strsave(rhs); mp->m_orig_str = vim_strsave(orig_rhs); - if (mp->m_keys == NULL || mp->m_str == NULL) { - free(mp->m_keys); - free(mp->m_str); - free(mp->m_orig_str); - free(mp); - retval = 4; /* no mem */ - goto theend; - } mp->m_keylen = (int)STRLEN(mp->m_keys); mp->m_noremap = noremap; mp->m_nowait = nowait; @@ -3328,11 +3314,9 @@ showmap ( /* Remove escaping of CSI, because "m_str" is in a format to be used * as typeahead. */ char_u *s = vim_strsave(mp->m_str); - if (s != NULL) { - vim_unescape_csi(s); - msg_outtrans_special(s, FALSE); - free(s); - } + vim_unescape_csi(s); + msg_outtrans_special(s, FALSE); + free(s); } if (p_verbose > 0) last_set_msg(mp->m_script_ID); @@ -3778,8 +3762,6 @@ eval_map_expr ( /* Remove escaping of CSI, because "str" is in a format to be used as * typeahead. */ expr = vim_strsave(str); - if (expr == NULL) - return NULL; vim_unescape_csi(expr); save_cmd = save_cmdline_alloc(); @@ -4325,10 +4307,8 @@ void add_map(char_u *map, int mode) p_cpo = (char_u *)""; /* Allow <> notation */ s = vim_strsave(map); - if (s != NULL) { - (void)do_map(0, s, mode, FALSE); - free(s); - } + (void)do_map(0, s, mode, FALSE); + free(s); p_cpo = cpo_save; } #endif -- cgit From 21784aeb005e78f04f4c1d398bc486be0a65248e Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Fri, 9 May 2014 03:30:26 -0300 Subject: Replace alloc() with xmalloc() and remove immediate OOM checks --- src/nvim/getchar.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 440349ff1b..d8e415c845 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -891,14 +891,8 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent) setcursor(); return FAIL; } - s1 = alloc(newlen); - if (s1 == NULL) /* out of memory */ - return FAIL; - s2 = alloc(newlen); - if (s2 == NULL) { /* out of memory */ - free(s1); - return FAIL; - } + s1 = xmalloc(newlen); + s2 = xmalloc(newlen); typebuf.tb_buflen = newlen; /* copy the old chars, before the insertion point */ @@ -1147,16 +1141,11 @@ static void may_sync_undo(void) /* * Make "typebuf" empty and allocate new buffers. - * Returns FAIL when out of memory. */ int alloc_typebuf(void) { - typebuf.tb_buf = alloc(TYPELEN_INIT); - typebuf.tb_noremap = alloc(TYPELEN_INIT); - if (typebuf.tb_buf == NULL || typebuf.tb_noremap == NULL) { - free_typebuf(); - return FAIL; - } + typebuf.tb_buf = xmalloc(TYPELEN_INIT); + typebuf.tb_noremap = xmalloc(TYPELEN_INIT); typebuf.tb_buflen = TYPELEN_INIT; typebuf.tb_off = 0; typebuf.tb_len = 0; @@ -3038,11 +3027,7 @@ do_map ( /* * Get here when adding a new entry to the maphash[] list or abbrlist. */ - mp = (mapblock_T *)alloc((unsigned)sizeof(mapblock_T)); - if (mp == NULL) { - retval = 4; /* no mem */ - goto theend; - } + mp = xmalloc(sizeof(mapblock_T)); /* If CTRL-C has been mapped, don't always use it for Interrupting */ if (*keys == Ctrl_C) @@ -3548,9 +3533,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) break; /* for (round) */ if (round == 1) { - *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); - if (*file == NULL) - return FAIL; + *file = (char_u **)xmalloc(count * sizeof(char_u *)); } } /* for (round) */ @@ -3813,7 +3796,7 @@ char_u *vim_strsave_escape_csi(char_u *p) char_u *s, *d; /* Need a buffer to hold up to three times as much. */ - res = alloc((unsigned)(STRLEN(p) * 3) + 1); + res = xmalloc(STRLEN(p) * 3 + 1); d = res; for (s = p; *s != NUL; ) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { -- cgit From 39a272c4db215c2f6043e8c5de5d2104d8118b4f Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 10 May 2014 01:09:33 -0300 Subject: Remove OOM checks: alloc_typebuf() --- src/nvim/getchar.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index d8e415c845..cc9f65fe29 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1142,7 +1142,7 @@ static void may_sync_undo(void) /* * Make "typebuf" empty and allocate new buffers. */ -int alloc_typebuf(void) +void alloc_typebuf(void) { typebuf.tb_buf = xmalloc(TYPELEN_INIT); typebuf.tb_noremap = xmalloc(TYPELEN_INIT); @@ -1154,7 +1154,6 @@ int alloc_typebuf(void) typebuf.tb_no_abbr_cnt = 0; if (++typebuf.tb_change_cnt == 0) typebuf.tb_change_cnt = 1; - return OK; } /* @@ -1182,11 +1181,7 @@ int save_typebuf(void) { init_typebuf(); saved_typebuf[curscript] = typebuf; - /* If out of memory: restore typebuf and close file. */ - if (alloc_typebuf() == FAIL) { - closescript(); - return FAIL; - } + alloc_typebuf(); return OK; } @@ -1202,10 +1197,8 @@ static int old_mouse_col; /* mouse_col related to old_char */ void save_typeahead(tasave_T *tp) { tp->save_typebuf = typebuf; - tp->typebuf_valid = (alloc_typebuf() == OK); - if (!tp->typebuf_valid) - typebuf = tp->save_typebuf; - + alloc_typebuf(); + tp->typebuf_valid = TRUE; tp->old_char = old_char; tp->old_mod_mask = old_mod_mask; old_char = -1; -- cgit From a2f6a53b68d73cb585dcb67ea19579d446810176 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 10 May 2014 01:11:34 -0300 Subject: Remove OOM checks: save_typebuf() --- src/nvim/getchar.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/getchar.c') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index cc9f65fe29..52322244e1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1177,12 +1177,11 @@ void free_typebuf(void) */ static typebuf_T saved_typebuf[NSCRIPT]; -int save_typebuf(void) +void save_typebuf(void) { init_typebuf(); saved_typebuf[curscript] = typebuf; alloc_typebuf(); - return OK; } static int old_char = -1; /* character put back by vungetc() */ @@ -1262,8 +1261,7 @@ openscript ( --curscript; return; } - if (save_typebuf() == FAIL) - return; + save_typebuf(); /* * Execute the commands from the file right now when using ":source!" -- cgit