From: Andrew Bartlett Date: Sat, 18 Jun 2016 03:49:24 +0000 (-0700) Subject: lib: talloc: Add _vasprintf_tc() which returns the struct talloc_chunk *, not the... X-Git-Tag: tdb-1.3.10~571 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=192c75730bac285e8516a49d9cf9c75a03d04e9c;p=thirdparty%2Fsamba.git lib: talloc: Add _vasprintf_tc() which returns the struct talloc_chunk *, not the talloc'ed pointer. Define talloc_vasprintf() in terms of _vasprintf_tc(). We will use _vasprintf_tc() internally later. Signed-off-by: Andrew Bartlett Reviewed-by: Jeremy Allison --- diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 3e844c4e752..6cc67e5f9fb 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -254,6 +254,9 @@ static inline void tc_memlimit_update_on_free(struct talloc_chunk *tc); static inline void _tc_set_name_const(struct talloc_chunk *tc, const char *name); +static struct talloc_chunk *_vasprintf_tc(const void *t, + const char *fmt, + va_list ap); typedef int (*talloc_destructor_t)(void *); @@ -2439,7 +2442,9 @@ _PUBLIC_ char *talloc_strndup_append_buffer(char *s, const char *a, size_t n) #endif #endif -_PUBLIC_ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) +static struct talloc_chunk *_vasprintf_tc(const void *t, + const char *fmt, + va_list ap) { int len; char *ret; @@ -2466,8 +2471,17 @@ _PUBLIC_ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) va_end(ap2); } - _tc_set_name_const(talloc_chunk_from_ptr(ret), ret); - return ret; + _tc_set_name_const(tc, ret); + return tc; +} + +_PUBLIC_ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) +{ + struct talloc_chunk *tc = _vasprintf_tc(t, fmt, ap); + if (tc == NULL) { + return NULL; + } + return TC_PTR_FROM_CHUNK(tc); }