From 42f1bd9b2228aaca4fb8a5597a3b5774f7ef6876 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Sat, 19 Apr 2014 02:12:47 -0300 Subject: No OOM error condition in ga_concat_strings(), concat_fnames(), concat_str() - xmallocz() is not static anymore. There are many use cases for this function in the codebase and we should start using it. - Simpler types in ga_concat_strings() --- src/path.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index d2b52ee93e..4914c681da 100644 --- a/src/path.c +++ b/src/path.c @@ -272,32 +272,26 @@ int vim_fnamencmp(char_u *x, char_u *y, size_t len) */ char_u *concat_fnames(char_u *fname1, char_u *fname2, int sep) { - char_u *dest; - - dest = alloc((unsigned)(STRLEN(fname1) + STRLEN(fname2) + 3)); - if (dest != NULL) { - STRCPY(dest, fname1); - if (sep) - add_pathsep(dest); - STRCAT(dest, fname2); + char_u *dest = xmalloc(STRLEN(fname1) + STRLEN(fname2) + 3); + + STRCPY(dest, fname1); + if (sep) { + add_pathsep(dest); } + STRCAT(dest, fname2); + return dest; } /* * Concatenate two strings and return the result in allocated memory. - * Returns NULL when out of memory. */ char_u *concat_str(char_u *str1, char_u *str2) { - char_u *dest; size_t l = STRLEN(str1); - - dest = alloc((unsigned)(l + STRLEN(str2) + 1L)); - if (dest != NULL) { - STRCPY(dest, str1); - STRCPY(dest + l, str2); - } + char_u *dest = xmalloc(l + STRLEN(str2) + 1); + STRCPY(dest, str1); + STRCPY(dest + l, str2); return dest; } @@ -916,8 +910,6 @@ expand_in_path ( paths = ga_concat_strings(&path_ga); ga_clear_strings(&path_ga); - if (paths == NULL) - return 0; files = globpath(paths, pattern, (flags & EW_ICASE) ? WILD_ICASE : 0); vim_free(paths); -- cgit