diff options
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r-- | src/nvim/file_search.c | 38 |
1 files changed, 15 insertions, 23 deletions
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; |