From: Christian Brauner Date: Thu, 11 Feb 2021 09:49:10 +0000 (+0100) Subject: string_utils: convert to strnprintf() X-Git-Tag: lxc-5.0.0~292^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4af24cb74075524c5ef650e6ef4850c95ac99880;p=thirdparty%2Flxc.git string_utils: convert to strnprintf() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index 9918299fb..574530bb4 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -276,9 +276,9 @@ char *lxc_deslashify(const char *path) char *lxc_append_paths(const char *first, const char *second) { + __do_free char *result = NULL; int ret; size_t len; - char *result = NULL; int pattern_type = 0; len = strlen(first) + strlen(second) + 1; @@ -287,20 +287,18 @@ char *lxc_append_paths(const char *first, const char *second) pattern_type = 1; } - result = calloc(1, len); + result = zalloc(len); if (!result) return NULL; if (pattern_type == 0) - ret = snprintf(result, len, "%s%s", first, second); + ret = strnprintf(result, len, "%s%s", first, second); else - ret = snprintf(result, len, "%s/%s", first, second); - if (ret < 0 || (size_t)ret >= len) { - free(result); + ret = strnprintf(result, len, "%s/%s", first, second); + if (ret < 0) return NULL; - } - return result; + return move_ptr(result); } bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)