From cf43e80d18ddf3dfeb99f46c51fd4d51747b814a Mon Sep 17 00:00:00 2001 From: sulincix Date: Tue, 19 Nov 2024 20:45:10 +0000 Subject: [PATCH] use va_arg instead of vsnprintf for calculate build string len --- src/ccode/string.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ccode/string.c b/src/ccode/string.c index eb618eb..841a4ac 100755 --- a/src/ccode/string.c +++ b/src/ccode/string.c @@ -221,7 +221,14 @@ char* build_string(char* format, ...) { va_start(args, format); /* Determine the size needed for the string */ - int size = vsnprintf(NULL, 0, format, args) + 1; + int size = strlen(format); + const char *arg; + + /* Count the number of arguments until we hit a NULL */ + while ((arg = va_arg(args, const char *)) != NULL) { + size+= strlen(arg); + } + va_end(args); /* Allocate memory for the string */ @@ -232,7 +239,7 @@ char* build_string(char* format, ...) { /* Format the string */ va_start(args, format); - vsnprintf(result, size, format, args); + sprintf(result, format, args); va_end(args); return result;