From: Richard Russon Date: Sat, 20 Apr 2019 01:43:54 +0000 (+0100) Subject: refactor mutt_str_append_item() X-Git-Tag: 2019-10-25~245^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0b99d940c8ae89dab23c7235d4453f48e1a1806;p=neomutt refactor mutt_str_append_item() --- diff --git a/mutt/string.c b/mutt/string.c index efd3a47ea..dc754b955 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -474,23 +474,21 @@ void mutt_str_replace(char **p, const char *s) * @param[in] item String to append * @param[in] sep separator between string item * - * This function appends a string to another separate them by sep - * if needed + * Append a string to another, separating them by sep if needed. * * This function alters the pointer of the caller. */ -void mutt_str_append_item(char **str, const char *item, int sep) +void mutt_str_append_item(char **str, const char *item, char sep) { if (!str || !item) return; - char *p = NULL; - size_t sz = strlen(item); - size_t ssz = *str ? strlen(*str) : 0; + size_t sz = mutt_str_strlen(item); + size_t ssz = mutt_str_strlen(*str); - mutt_mem_realloc(str, ssz + ((ssz && sep) ? 1 : 0) + sz + 1); - p = *str + ssz; - if (sep && ssz) + mutt_mem_realloc(str, ssz + (((ssz > 0) && (sep != '\0')) ? 1 : 0) + sz + 1); + char *p = *str + ssz; + if ((ssz > 0) && (sep != '\0')) *p++ = sep; memcpy(p, item, sz + 1); } diff --git a/mutt/string2.h b/mutt/string2.h index a77eda023..1f711052f 100644 --- a/mutt/string2.h +++ b/mutt/string2.h @@ -68,7 +68,7 @@ enum CaseSensitivity }; void mutt_str_adjust(char **p); -void mutt_str_append_item(char **str, const char *item, int sep); +void mutt_str_append_item(char **str, const char *item, char sep); int mutt_str_asprintf(char **strp, const char *fmt, ...); int mutt_str_atoi(const char *str, int *dst); int mutt_str_atol(const char *str, long *dst);