diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-04-04 14:24:13 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-11 12:57:59 -0300 |
commit | 86279cefae74ead8c740575d294ef06e12aa7da8 (patch) | |
tree | b0be9f06cb3aec89629c8ab8bb60a6cddce010ae | |
parent | 3fcdb2ab29f6285b4b5b4fd706db54a98b1a773f (diff) | |
download | rneovim-86279cefae74ead8c740575d294ef06e12aa7da8.tar.gz rneovim-86279cefae74ead8c740575d294ef06e12aa7da8.tar.bz2 rneovim-86279cefae74ead8c740575d294ef06e12aa7da8.zip |
Remove more OOM error handling code
From the functions:
- ExpandBufnames
- buf_modname()
- do_autocmd_event()
- ff_create_stack_element()
- ff_get_visited_list()
- ins_complete()
- msg_show_console_dialog()
- prt_find_resource()
- vim_findfile_init()
TODO: refactor msg_show_console_dialog() to make sure it doesn't ever return
NULL.
-rw-r--r-- | src/buffer.c | 6 | ||||
-rw-r--r-- | src/diff.c | 1 | ||||
-rw-r--r-- | src/edit.c | 6 | ||||
-rw-r--r-- | src/file_search.c | 54 | ||||
-rw-r--r-- | src/fileio.c | 8 | ||||
-rw-r--r-- | src/hardcopy.c | 2 | ||||
-rw-r--r-- | src/message.c | 4 |
7 files changed, 22 insertions, 59 deletions
diff --git a/src/buffer.c b/src/buffer.c index 2f214f45ac..d25ed10ac7 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1877,12 +1877,6 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) break; if (round == 1) { *file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); - if (*file == NULL) { - vim_regfree(prog); - if (patc != pat) - vim_free(patc); - return FAIL; - } } } vim_regfree(prog); diff --git a/src/diff.c b/src/diff.c index eb1325b76e..90bdbf0850 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1403,7 +1403,6 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) notset = TRUE; } -done: fclose(fd); } diff --git a/src/edit.c b/src/edit.c index fb60fb25c1..acb05f6588 100644 --- a/src/edit.c +++ b/src/edit.c @@ -4345,8 +4345,6 @@ static int ins_complete(int c) /* we need up to 2 extra chars for the prefix */ compl_pattern = alloc(quote_meta(NULL, line + compl_col, compl_length) + 2); - if (compl_pattern == NULL) - return FAIL; if (!vim_iswordp(line + compl_col) || (compl_col > 0 && ( @@ -4392,16 +4390,12 @@ static int ins_complete(int c) * alloc(7) is enough -- Acevedo */ compl_pattern = alloc(7); - if (compl_pattern == NULL) - return FAIL; STRCPY((char *)compl_pattern, "\\<"); (void)quote_meta(compl_pattern + 2, line + compl_col, 1); STRCAT((char *)compl_pattern, "\\k"); } else { compl_pattern = alloc(quote_meta(NULL, line + compl_col, compl_length) + 2); - if (compl_pattern == NULL) - return FAIL; STRCPY((char *)compl_pattern, "\\<"); (void)quote_meta(compl_pattern + 2, line + compl_col, compl_length); diff --git a/src/file_search.c b/src/file_search.c index d4a3e35094..57ff7ad3f4 100644 --- a/src/file_search.c +++ b/src/file_search.c @@ -280,8 +280,6 @@ vim_findfile_init ( search_ctx = search_ctx_arg; else { search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T)); - if (search_ctx == NULL) - goto error_return; memset(search_ctx, 0, sizeof(ff_search_ctx_T)); } search_ctx->ffsc_find_what = find_what; @@ -309,8 +307,6 @@ vim_findfile_init ( if (ff_expand_buffer == NULL) { ff_expand_buffer = (char_u*)alloc(MAXPATHL); - if (ff_expand_buffer == NULL) - goto error_return; } /* Store information on starting dir now if path is relative. @@ -382,32 +378,30 @@ vim_findfile_init ( search_ctx->ffsc_stopdirs_v = (char_u **)alloc((unsigned)sizeof(char_u *)); - if (search_ctx->ffsc_stopdirs_v != NULL) { - do { - char_u *helper; - void *ptr; - - helper = walker; - ptr = xrealloc(search_ctx->ffsc_stopdirs_v, - (dircount + 1) * sizeof(char_u *)); - search_ctx->ffsc_stopdirs_v = ptr; - walker = vim_strchr(walker, ';'); - if (walker) { - search_ctx->ffsc_stopdirs_v[dircount-1] = - vim_strnsave(helper, (int)(walker - helper)); - walker++; - } else - /* this might be "", which means ascent till top - * of directory tree. - */ - search_ctx->ffsc_stopdirs_v[dircount-1] = - vim_strsave(helper); + do { + char_u *helper; + void *ptr; + + helper = walker; + ptr = xrealloc(search_ctx->ffsc_stopdirs_v, + (dircount + 1) * sizeof(char_u *)); + search_ctx->ffsc_stopdirs_v = ptr; + walker = vim_strchr(walker, ';'); + if (walker) { + search_ctx->ffsc_stopdirs_v[dircount-1] = + vim_strnsave(helper, (int)(walker - helper)); + walker++; + } else + /* this might be "", which means ascent till top + * of directory tree. + */ + search_ctx->ffsc_stopdirs_v[dircount-1] = + vim_strsave(helper); - dircount++; + dircount++; - } while (walker != NULL); - search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; - } + } while (walker != NULL); + search_ctx->ffsc_stopdirs_v[dircount-1] = NULL; } search_ctx->ffsc_level = level; @@ -1074,8 +1068,6 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l * if we reach this we didn't find a list and we have to allocate new list */ retptr = (ff_visited_list_hdr_T*)alloc((unsigned)sizeof(*retptr)); - if (retptr == NULL) - return NULL; retptr->ffvl_visited_list = NULL; retptr->ffvl_filename = vim_strsave(filename); @@ -1212,8 +1204,6 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in ff_stack_T *new; new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T)); - if (new == NULL) - return NULL; new->ffs_prev = NULL; new->ffs_filearray = NULL; diff --git a/src/fileio.c b/src/fileio.c index 7f2d7b1098..5bf75e34c4 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4739,8 +4739,6 @@ buf_modname ( */ if (fname == NULL || *fname == NUL) { retval = alloc((unsigned)(MAXPATHL + extlen + 3)); - if (retval == NULL) - return NULL; if (os_dirname(retval, MAXPATHL) == FAIL || (fnamelen = (int)STRLEN(retval)) == 0) { vim_free(retval); @@ -4756,8 +4754,6 @@ buf_modname ( } else { fnamelen = (int)STRLEN(fname); retval = alloc((unsigned)(fnamelen + extlen + 3)); - if (retval == NULL) - return NULL; STRCPY(retval, fname); } @@ -6772,8 +6768,6 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, } ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat)); - if (ap == NULL) - return FAIL; ap->pat = vim_strnsave(pat, patlen); ap->patlen = patlen; if (ap->pat == NULL) { @@ -6815,8 +6809,6 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, while ((ac = *prev_ac) != NULL) prev_ac = &ac->next; ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd)); - if (ac == NULL) - return FAIL; ac->cmd = vim_strsave(cmd); ac->scriptID = current_SID; if (ac->cmd == NULL) { diff --git a/src/hardcopy.c b/src/hardcopy.c index 0d3715a8a7..fcbcedba37 100644 --- a/src/hardcopy.c +++ b/src/hardcopy.c @@ -1596,8 +1596,6 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) int retval; buffer = alloc(MAXPATHL + 1); - if (buffer == NULL) - return FALSE; vim_strncpy(resource->name, (char_u *)name, 63); /* Look for named resource file in runtimepath */ diff --git a/src/message.c b/src/message.c index 6553e0bd5f..5ec87c6297 100644 --- a/src/message.c +++ b/src/message.c @@ -2941,12 +2941,8 @@ static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfl */ vim_free(confirm_msg); confirm_msg = alloc(len); - if (confirm_msg == NULL) - return NULL; *confirm_msg = NUL; hotk = alloc(lenhotkey); - if (hotk == NULL) - return NULL; *confirm_msg = '\n'; STRCPY(confirm_msg + 1, message); |