From f9f55ad5fcda943f6747d6bef72f6d9d00a263c4 Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 8 Feb 2006 23:44:17 +0000 Subject: r13397: Propagate the error return from vsnprintf to trap the case where we aren't linked against a C99 vsnprintf. (This used to be commit 23782f899aaa5fe488d86d5e67e91be99ff7a146) --- source4/lib/talloc/talloc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index ac2fedebdc..6b3328420d 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -1011,7 +1011,9 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) VA_COPY(ap2, ap); - len = vsnprintf(NULL, 0, fmt, ap2); + if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) { + return NULL; + } ret = _talloc(t, len+1); if (ret) { @@ -1060,7 +1062,15 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) VA_COPY(ap2, ap); s_len = tc->size - 1; - len = vsnprintf(NULL, 0, fmt, ap2); + if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) { + /* Either the vsnprintf failed or the format resulted in + * no characters being formatted. In the former case, we + * ought to return NULL, in the latter we ought to return + * the original string. Most current callers of this + * function expect it to never return NULL. + */ + return s; + } s = talloc_realloc(NULL, s, char, s_len + len+1); if (!s) return NULL; -- cgit