X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fstring-utils%2Fstring-utils.cpp;h=4f727e2e8ed0fe9f407249e538a4dfe1b80d7f85;hb=51a7b11ec8712e8888af09cc3d3df3bb848f70e9;hp=63de5267442721ac861ffb666c6a6b42d332ccb4;hpb=40b2a4a793c81221a28f822d07135069456ea021;p=lttng-tools.git diff --git a/src/common/string-utils/string-utils.cpp b/src/common/string-utils/string-utils.cpp index 63de52674..4f727e2e8 100644 --- a/src/common/string-utils/string-utils.cpp +++ b/src/common/string-utils/string-utils.cpp @@ -395,6 +395,7 @@ int strutils_appendf(char **s, const char *fmt, ...) { char *new_str; size_t oldlen = (*s) ? strlen(*s) : 0; + size_t addlen = 0; int ret; va_list args; @@ -408,7 +409,8 @@ int strutils_appendf(char **s, const char *fmt, ...) } /* Allocate space for old string + new string + \0. */ - new_str = zmalloc(oldlen + ret + 1); + addlen = ret + 1; + new_str = zmalloc(oldlen + addlen); if (!new_str) { ret = -ENOMEM; goto end; @@ -421,7 +423,7 @@ int strutils_appendf(char **s, const char *fmt, ...) /* Format new string in-place. */ va_start(args, fmt); - ret = vsprintf(&new_str[oldlen], fmt, args); + ret = vsnprintf(&new_str[oldlen], addlen, fmt, args); va_end(args); if (ret == -1) {