X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Fmalloc.c;h=51b8ff6aecf93e7015b08ed2c13cf9d653d91122;hb=6cc9575148671ed743b86687b0d7e1b876a99114;hp=018a0c0d95e403f7e879f450985cd06621f979b6;hpb=4f0a5e7572a4257894b4bfede42c26d65152609e;p=catta diff --git a/avahi-common/malloc.c b/avahi-common/malloc.c index 018a0c0..51b8ff6 100644 --- a/avahi-common/malloc.c +++ b/avahi-common/malloc.c @@ -31,6 +31,14 @@ #include "malloc.h" +#ifndef va_copy +#ifdef __va_copy +#define va_copy(DEST,SRC) __va_copy((DEST),(SRC)) +#else +#define va_copy(DEST,SRC) memcpy(&(DEST), &(SRC), sizeof(va_list)) +#endif +#endif + static const AvahiAllocator *allocator = NULL; static void oom(void) AVAHI_GCC_NORETURN; @@ -169,16 +177,16 @@ char *avahi_strdup(const char *s) { char *avahi_strndup(const char *s, size_t max) { char *r; size_t size; + const char *p; if (!s) return NULL; - size = strlen(s); - - if (size > max) - size = max; + for (p = s, size = 0; + size < max && *p; + p++, size++); - if (!(r = avahi_malloc(size+1))) + if (!(r = avahi_new(char, size+1))) return NULL; memcpy(r, s, size); @@ -192,7 +200,7 @@ void avahi_set_allocator(const AvahiAllocator *a) { } char *avahi_strdup_vprintf(const char *fmt, va_list ap) { - size_t len = 100; + size_t len = 80; char *buf; assert(fmt); @@ -203,8 +211,11 @@ char *avahi_strdup_vprintf(const char *fmt, va_list ap) { for (;;) { int n; char *nbuf; - - n = vsnprintf(buf, len, fmt, ap); + va_list ap2; + + va_copy (ap2, ap); + n = vsnprintf(buf, len, fmt, ap2); + va_end (ap2); if (n >= 0 && n < (int) len) return buf;