From 340d35be2d3f29a3176d86c0960398c2e36f921f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 22 Mar 2005 04:22:39 +0000 Subject: r5937: - performance improvement to talloc_asprintf_append() - allow standalone talloc to use gcc printf attributes (This used to be commit e25aa54e962796e6e7385afed57aa287ef6f869d) --- source4/lib/talloc/talloc.c | 7 ++----- source4/lib/talloc/talloc.h | 8 ++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index 291ee5a8bf..72765448c7 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -946,16 +946,13 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINT static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) { + struct talloc_chunk *tc = talloc_chunk_from_ptr(s); int len, s_len; va_list ap2; VA_COPY(ap2, ap); - if (s) { - s_len = strlen(s); - } else { - s_len = 0; - } + s_len = tc->size - 1; len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(NULL, s, char, s_len + len+1); diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index 0a98881054..f639f3c8cf 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -75,8 +75,16 @@ typedef void TALLOC_CTX; #endif #ifndef PRINTF_ATTRIBUTE +#if (__GNUC__ >= 3) +/** Use gcc attribute to check printf fns. a1 is the 1-based index of + * the parameter containing the format, and a2 the index of the first + * argument. Note that some gcc 2.x versions don't handle this + * properly **/ +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) +#else #define PRINTF_ATTRIBUTE(a1, a2) #endif +#endif /* The following definitions come from talloc.c */ -- cgit