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()
This commit is contained in:
Felipe Oliveira Carvalho
2014-04-19 02:12:47 -03:00
committed by Thiago de Arruda
parent 4b6b9117b3
commit 42f1bd9b22
10 changed files with 54 additions and 97 deletions

View File

@@ -102,28 +102,26 @@ void ga_remove_duplicate_strings(garray_T *gap)
///
/// @param gap
///
/// @returns NULL when out of memory.
/// @returns the concatenated strings
char_u* ga_concat_strings(garray_T *gap)
{
int i;
int len = 0;
char_u *s;
size_t len = 0;
for (i = 0; i < gap->ga_len; ++i) {
len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + 1;
for (int i = 0; i < gap->ga_len; ++i) {
len += strlen(((char **)(gap->ga_data))[i]) + 1;
}
s = alloc(len + 1);
char *s = xmallocz(len);
*s = NUL;
for (i = 0; i < gap->ga_len; ++i) {
for (int i = 0; i < gap->ga_len; ++i) {
if (*s != NUL) {
STRCAT(s, ",");
strcat(s, ",");
}
STRCAT(s, ((char_u **)(gap->ga_data))[i]);
strcat(s, ((char **)(gap->ga_data))[i]);
}
return s;
return (char_u *)s;
}
/// Concatenate a string to a growarray which contains characters.