mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06: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;
|
break;
|
||||||
if (round == 1) {
|
if (round == 1) {
|
||||||
*file = (char_u **)alloc((unsigned)(count * sizeof(char_u *)));
|
*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);
|
vim_regfree(prog);
|
||||||
|
@ -1403,7 +1403,6 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname)
|
|||||||
notset = TRUE;
|
notset = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4345,8 +4345,6 @@ static int ins_complete(int c)
|
|||||||
/* we need up to 2 extra chars for the prefix */
|
/* we need up to 2 extra chars for the prefix */
|
||||||
compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
||||||
compl_length) + 2);
|
compl_length) + 2);
|
||||||
if (compl_pattern == NULL)
|
|
||||||
return FAIL;
|
|
||||||
if (!vim_iswordp(line + compl_col)
|
if (!vim_iswordp(line + compl_col)
|
||||||
|| (compl_col > 0
|
|| (compl_col > 0
|
||||||
&& (
|
&& (
|
||||||
@ -4392,16 +4390,12 @@ static int ins_complete(int c)
|
|||||||
* alloc(7) is enough -- Acevedo
|
* alloc(7) is enough -- Acevedo
|
||||||
*/
|
*/
|
||||||
compl_pattern = alloc(7);
|
compl_pattern = alloc(7);
|
||||||
if (compl_pattern == NULL)
|
|
||||||
return FAIL;
|
|
||||||
STRCPY((char *)compl_pattern, "\\<");
|
STRCPY((char *)compl_pattern, "\\<");
|
||||||
(void)quote_meta(compl_pattern + 2, line + compl_col, 1);
|
(void)quote_meta(compl_pattern + 2, line + compl_col, 1);
|
||||||
STRCAT((char *)compl_pattern, "\\k");
|
STRCAT((char *)compl_pattern, "\\k");
|
||||||
} else {
|
} else {
|
||||||
compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
compl_pattern = alloc(quote_meta(NULL, line + compl_col,
|
||||||
compl_length) + 2);
|
compl_length) + 2);
|
||||||
if (compl_pattern == NULL)
|
|
||||||
return FAIL;
|
|
||||||
STRCPY((char *)compl_pattern, "\\<");
|
STRCPY((char *)compl_pattern, "\\<");
|
||||||
(void)quote_meta(compl_pattern + 2, line + compl_col,
|
(void)quote_meta(compl_pattern + 2, line + compl_col,
|
||||||
compl_length);
|
compl_length);
|
||||||
|
@ -280,8 +280,6 @@ vim_findfile_init (
|
|||||||
search_ctx = search_ctx_arg;
|
search_ctx = search_ctx_arg;
|
||||||
else {
|
else {
|
||||||
search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T));
|
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));
|
memset(search_ctx, 0, sizeof(ff_search_ctx_T));
|
||||||
}
|
}
|
||||||
search_ctx->ffsc_find_what = find_what;
|
search_ctx->ffsc_find_what = find_what;
|
||||||
@ -309,8 +307,6 @@ vim_findfile_init (
|
|||||||
|
|
||||||
if (ff_expand_buffer == NULL) {
|
if (ff_expand_buffer == NULL) {
|
||||||
ff_expand_buffer = (char_u*)alloc(MAXPATHL);
|
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.
|
/* Store information on starting dir now if path is relative.
|
||||||
@ -382,32 +378,30 @@ vim_findfile_init (
|
|||||||
search_ctx->ffsc_stopdirs_v =
|
search_ctx->ffsc_stopdirs_v =
|
||||||
(char_u **)alloc((unsigned)sizeof(char_u *));
|
(char_u **)alloc((unsigned)sizeof(char_u *));
|
||||||
|
|
||||||
if (search_ctx->ffsc_stopdirs_v != NULL) {
|
do {
|
||||||
do {
|
char_u *helper;
|
||||||
char_u *helper;
|
void *ptr;
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
helper = walker;
|
helper = walker;
|
||||||
ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
|
ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
|
||||||
(dircount + 1) * sizeof(char_u *));
|
(dircount + 1) * sizeof(char_u *));
|
||||||
search_ctx->ffsc_stopdirs_v = ptr;
|
search_ctx->ffsc_stopdirs_v = ptr;
|
||||||
walker = vim_strchr(walker, ';');
|
walker = vim_strchr(walker, ';');
|
||||||
if (walker) {
|
if (walker) {
|
||||||
search_ctx->ffsc_stopdirs_v[dircount-1] =
|
search_ctx->ffsc_stopdirs_v[dircount-1] =
|
||||||
vim_strnsave(helper, (int)(walker - helper));
|
vim_strnsave(helper, (int)(walker - helper));
|
||||||
walker++;
|
walker++;
|
||||||
} else
|
} else
|
||||||
/* this might be "", which means ascent till top
|
/* this might be "", which means ascent till top
|
||||||
* of directory tree.
|
* of directory tree.
|
||||||
*/
|
*/
|
||||||
search_ctx->ffsc_stopdirs_v[dircount-1] =
|
search_ctx->ffsc_stopdirs_v[dircount-1] =
|
||||||
vim_strsave(helper);
|
vim_strsave(helper);
|
||||||
|
|
||||||
dircount++;
|
dircount++;
|
||||||
|
|
||||||
} while (walker != NULL);
|
} while (walker != NULL);
|
||||||
search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
|
search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
search_ctx->ffsc_level = level;
|
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
|
* 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));
|
retptr = (ff_visited_list_hdr_T*)alloc((unsigned)sizeof(*retptr));
|
||||||
if (retptr == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
retptr->ffvl_visited_list = NULL;
|
retptr->ffvl_visited_list = NULL;
|
||||||
retptr->ffvl_filename = vim_strsave(filename);
|
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;
|
ff_stack_T *new;
|
||||||
|
|
||||||
new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T));
|
new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T));
|
||||||
if (new == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
new->ffs_prev = NULL;
|
new->ffs_prev = NULL;
|
||||||
new->ffs_filearray = NULL;
|
new->ffs_filearray = NULL;
|
||||||
|
@ -4739,8 +4739,6 @@ buf_modname (
|
|||||||
*/
|
*/
|
||||||
if (fname == NULL || *fname == NUL) {
|
if (fname == NULL || *fname == NUL) {
|
||||||
retval = alloc((unsigned)(MAXPATHL + extlen + 3));
|
retval = alloc((unsigned)(MAXPATHL + extlen + 3));
|
||||||
if (retval == NULL)
|
|
||||||
return NULL;
|
|
||||||
if (os_dirname(retval, MAXPATHL) == FAIL ||
|
if (os_dirname(retval, MAXPATHL) == FAIL ||
|
||||||
(fnamelen = (int)STRLEN(retval)) == 0) {
|
(fnamelen = (int)STRLEN(retval)) == 0) {
|
||||||
vim_free(retval);
|
vim_free(retval);
|
||||||
@ -4756,8 +4754,6 @@ buf_modname (
|
|||||||
} else {
|
} else {
|
||||||
fnamelen = (int)STRLEN(fname);
|
fnamelen = (int)STRLEN(fname);
|
||||||
retval = alloc((unsigned)(fnamelen + extlen + 3));
|
retval = alloc((unsigned)(fnamelen + extlen + 3));
|
||||||
if (retval == NULL)
|
|
||||||
return NULL;
|
|
||||||
STRCPY(retval, fname);
|
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));
|
ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat));
|
||||||
if (ap == NULL)
|
|
||||||
return FAIL;
|
|
||||||
ap->pat = vim_strnsave(pat, patlen);
|
ap->pat = vim_strnsave(pat, patlen);
|
||||||
ap->patlen = patlen;
|
ap->patlen = patlen;
|
||||||
if (ap->pat == NULL) {
|
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)
|
while ((ac = *prev_ac) != NULL)
|
||||||
prev_ac = &ac->next;
|
prev_ac = &ac->next;
|
||||||
ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd));
|
ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd));
|
||||||
if (ac == NULL)
|
|
||||||
return FAIL;
|
|
||||||
ac->cmd = vim_strsave(cmd);
|
ac->cmd = vim_strsave(cmd);
|
||||||
ac->scriptID = current_SID;
|
ac->scriptID = current_SID;
|
||||||
if (ac->cmd == NULL) {
|
if (ac->cmd == NULL) {
|
||||||
|
@ -1596,8 +1596,6 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource)
|
|||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
buffer = alloc(MAXPATHL + 1);
|
buffer = alloc(MAXPATHL + 1);
|
||||||
if (buffer == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
vim_strncpy(resource->name, (char_u *)name, 63);
|
vim_strncpy(resource->name, (char_u *)name, 63);
|
||||||
/* Look for named resource file in runtimepath */
|
/* 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);
|
vim_free(confirm_msg);
|
||||||
confirm_msg = alloc(len);
|
confirm_msg = alloc(len);
|
||||||
if (confirm_msg == NULL)
|
|
||||||
return NULL;
|
|
||||||
*confirm_msg = NUL;
|
*confirm_msg = NUL;
|
||||||
hotk = alloc(lenhotkey);
|
hotk = alloc(lenhotkey);
|
||||||
if (hotk == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
*confirm_msg = '\n';
|
*confirm_msg = '\n';
|
||||||
STRCPY(confirm_msg + 1, message);
|
STRCPY(confirm_msg + 1, message);
|
||||||
|
Loading…
Reference in New Issue
Block a user