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/file_search.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'src/nvim/file_search.c') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index dbef8b422d..5faa112150 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -322,8 +322,6 @@ vim_findfile_init ( search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); } else search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); - if (search_ctx->ffsc_start_dir == NULL) - goto error_return; if (*++path != NUL) ++path; } else if (*path == NUL || !vim_isAbsName(path)) { @@ -344,8 +342,6 @@ vim_findfile_init ( goto error_return; search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); - if (search_ctx->ffsc_start_dir == NULL) - goto error_return; #ifdef BACKSLASH_IN_FILENAME /* A path that starts with "/dir" is relative to the drive, not to the @@ -458,9 +454,6 @@ vim_findfile_init ( } ff_expand_buffer[len] = NUL; search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); - - if (search_ctx->ffsc_wc_path == NULL) - goto error_return; } else search_ctx->ffsc_fix_path = vim_strsave(path); @@ -469,8 +462,6 @@ vim_findfile_init ( * This is needed if the parameter path is fully qualified. */ search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); - if (search_ctx->ffsc_start_dir == NULL) - goto error_return; search_ctx->ffsc_fix_path[0] = NUL; } @@ -536,11 +527,7 @@ vim_findfile_init ( goto error_return; ff_push(search_ctx, sptr); - search_ctx->ffsc_file_to_search = vim_strsave(filename); - if (search_ctx->ffsc_file_to_search == NULL) - goto error_return; - return search_ctx; error_return: @@ -1070,10 +1057,6 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l retptr->ffvl_visited_list = NULL; retptr->ffvl_filename = vim_strsave(filename); - if (retptr->ffvl_filename == NULL) { - free(retptr); - return NULL; - } retptr->ffvl_next = *list_headp; *list_headp = retptr; @@ -1185,9 +1168,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * */ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, int star_star_empty) { - ff_stack_T *new; - - new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T)); + ff_stack_T *new = xmalloc(sizeof(ff_stack_T)); new->ffs_prev = NULL; new->ffs_filearray = NULL; @@ -1206,13 +1187,6 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in wc_part = (char_u *)""; new->ffs_wc_path = vim_strsave(wc_part); - if (new->ffs_fix_path == NULL - || new->ffs_wc_path == NULL - ) { - ff_free_stack_element(new); - new = NULL; - } - return new; } @@ -1429,10 +1403,6 @@ find_file_in_path_option ( free(ff_file_to_find); ff_file_to_find = vim_strsave(NameBuff); - if (ff_file_to_find == NULL) { /* out of memory */ - file_name = NULL; - goto theend; - } } rel_to_curdir = (ff_file_to_find[0] == '.' -- 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/file_search.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/nvim/file_search.c') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 5faa112150..ffc6497aca 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -278,8 +278,7 @@ vim_findfile_init ( if (search_ctx_arg != NULL) search_ctx = search_ctx_arg; else { - search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T)); - memset(search_ctx, 0, sizeof(ff_search_ctx_T)); + search_ctx = xcalloc(1, sizeof(ff_search_ctx_T)); } search_ctx->ffsc_find_what = find_what; search_ctx->ffsc_tagfile = tagfile; @@ -305,7 +304,7 @@ vim_findfile_init ( } if (ff_expand_buffer == NULL) { - ff_expand_buffer = (char_u*)alloc(MAXPATHL); + ff_expand_buffer = xmalloc(MAXPATHL); } /* Store information on starting dir now if path is relative. @@ -370,8 +369,7 @@ vim_findfile_init ( walker++; dircount = 1; - search_ctx->ffsc_stopdirs_v = - (char_u **)alloc((unsigned)sizeof(char_u *)); + search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *)); do { char_u *helper; @@ -474,9 +472,8 @@ vim_findfile_init ( STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); add_pathsep(ff_expand_buffer); { - int eb_len = (int)STRLEN(ff_expand_buffer); - char_u *buf = alloc(eb_len - + (int)STRLEN(search_ctx->ffsc_fix_path) + 1); + size_t eb_len = STRLEN(ff_expand_buffer); + char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1); STRCPY(buf, ff_expand_buffer); STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); @@ -498,9 +495,9 @@ vim_findfile_init ( if (search_ctx->ffsc_wc_path != NULL) { wc_path = vim_strsave(search_ctx->ffsc_wc_path); - temp = alloc((int)(STRLEN(search_ctx->ffsc_wc_path) - + STRLEN(search_ctx->ffsc_fix_path + len) - + 1)); + temp = xmalloc(STRLEN(search_ctx->ffsc_wc_path) + + STRLEN(search_ctx->ffsc_fix_path + len) + + 1); } if (temp == NULL || wc_path == NULL) { @@ -610,8 +607,7 @@ char_u *vim_findfile(void *search_ctx_arg) * filepath is used as buffer for various actions and as the storage to * return a found filename. */ - if ((file_path = alloc((int)MAXPATHL)) == NULL) - return NULL; + file_path = xmalloc(MAXPATHL); /* store the end of the start dir -- needed for upward search */ if (search_ctx->ffsc_start_dir != NULL) @@ -763,12 +759,9 @@ char_u *vim_findfile(void *search_ctx_arg) * If the path is a URL don't try this. */ if (path_with_url(dirptrs[0])) { - stackp->ffs_filearray = (char_u **) - alloc((unsigned)sizeof(char *)); - if ((stackp->ffs_filearray[0] = vim_strsave(dirptrs[0])) != NULL) - stackp->ffs_filearray_size = 1; - else - stackp->ffs_filearray_size = 0; + stackp->ffs_filearray = (char_u **)xmalloc(sizeof(char *)); + stackp->ffs_filearray[0] = vim_strsave(dirptrs[0]); + stackp->ffs_filearray_size = 1; } else /* Add EW_NOTWILD because the expanded path may contain * wildcard characters that are to be taken literally. @@ -1053,7 +1046,7 @@ 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)); + retptr = xmalloc(sizeof(*retptr)); retptr->ffvl_visited_list = NULL; retptr->ffvl_filename = vim_strsave(filename); @@ -1139,8 +1132,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * /* * New file/dir. Add it to the list of visited files/dirs. */ - vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T) - + STRLEN(ff_expand_buffer))); + vp = xmalloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer)); if (!url) { vp->ffv_dev_valid = TRUE; @@ -1495,7 +1487,7 @@ find_file_in_path_option ( break; } - buf = alloc((int)(MAXPATHL)); + buf = xmalloc(MAXPATHL); /* copy next path */ buf[0] = 0; -- cgit From 1a2364f74e78f82e92e95e387ce18fbbfe528a74 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Mon, 12 May 2014 14:27:20 -0300 Subject: Remove OOM checks: ff_create_stack_element() --- src/nvim/file_search.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/nvim/file_search.c') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index ffc6497aca..0ff02b85bf 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -520,9 +520,6 @@ vim_findfile_init ( search_ctx->ffsc_wc_path, level, 0); - if (sptr == NULL) - goto error_return; - ff_push(search_ctx, sptr); search_ctx->ffsc_file_to_search = vim_strsave(filename); return search_ctx; @@ -949,8 +946,6 @@ char_u *vim_findfile(void *search_ctx_arg) /* create a new stack entry */ sptr = ff_create_stack_element(file_path, search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); - if (sptr == NULL) - break; ff_push(search_ctx, sptr); } else break; -- cgit