mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
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.
This commit is contained in:
parent
3fcdb2ab29
commit
86279cefae
@ -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);
|
||||
|
@ -1403,7 +1403,6 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname)
|
||||
notset = TRUE;
|
||||
}
|
||||
|
||||
done:
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
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);
|
||||
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;
|
||||
|
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user