X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fsprintf_alloc.c;h=82a847160edd9a6f52097d11c8705df73b2e82d9;hp=e2513ecee5fda05c59861f6d08d0205d71270faa;hb=HEAD;hpb=7e8e45766b6fbf8c3ea443646af259f2943e4ef2 diff --git a/libopkg/sprintf_alloc.c b/libopkg/sprintf_alloc.c index e2513ec..82a8471 100644 --- a/libopkg/sprintf_alloc.c +++ b/libopkg/sprintf_alloc.c @@ -18,24 +18,22 @@ #include "sprintf_alloc.h" #include "libbb/libbb.h" -void -sprintf_alloc(char **str, const char *fmt, ...) +void sprintf_alloc(char **str, const char *fmt, ...) { va_list ap; int n; - unsigned int size = 1; + unsigned int size = 0; - *str = xcalloc(1, size); + *str = NULL; for (;;) { va_start(ap, fmt); - n = vsnprintf (*str, size, fmt, ap); + n = vsnprintf(*str, size, fmt, ap); va_end(ap); if (n < 0) { fprintf(stderr, "%s: encountered an output or encoding" - " error during vsnprintf.\n", - __FUNCTION__); + " error during vsnprintf.\n", __FUNCTION__); exit(EXIT_FAILURE); } @@ -43,7 +41,7 @@ sprintf_alloc(char **str, const char *fmt, ...) break; /* Truncated, try again with more space. */ - size = n+1; + size = n + 1; *str = xrealloc(*str, size); } }