r23796: main COPYING file for samba4, plus some formatting varients
[samba.git] / source / lib / talloc / talloc.c
index 15a44bd0d99298661fe70a7f9957177507dc99ac..a28e9defadaeef4348b6ad6a7bf6f76606b6c87b 100644 (file)
@@ -15,7 +15,7 @@
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
+   version 3 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -1086,7 +1086,6 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name)
        return p;
 }
 
-
 /*
   memdup with a talloc. 
 */
@@ -1138,6 +1137,8 @@ char *talloc_append_string(const void *t, char *orig, const char *append)
        /* append the string with the trailing \0 */
        memcpy(&ret[olen], append, alenz);
 
+       _talloc_set_name_const(ret, ret);
+
        return ret;
 }
 
@@ -1174,10 +1175,11 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
        va_list ap2;
        char c;
        
-       va_copy(ap2, ap);
-
        /* this call looks strange, but it makes it work on older solaris boxes */
-       if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
+       va_copy(ap2, ap);
+       len = vsnprintf(&c, 1, fmt, ap2);
+       va_end(ap2);
+       if (len < 0) {
                return NULL;
        }
 
@@ -1185,6 +1187,7 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
        if (ret) {
                va_copy(ap2, ap);
                vsnprintf(ret, len+1, fmt, ap2);
+               va_end(ap2);
                _talloc_set_name_const(ret, ret);
        }
 
@@ -1226,10 +1229,13 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
 
        tc = talloc_chunk_from_ptr(s);
 
+       s_len = tc->size - 1;
+
        va_copy(ap2, ap);
+       len = vsnprintf(&c, 1, fmt, ap2);
+       va_end(ap2);
 
-       s_len = tc->size - 1;
-       if ((len = vsnprintf(&c, 1, fmt, ap2)) <= 0) {
+       if (len <= 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
@@ -1243,8 +1249,8 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
        if (!s) return NULL;
 
        va_copy(ap2, ap);
-
        vsnprintf(s+s_len, len+1, fmt, ap2);
+       va_end(ap2);
        _talloc_set_name_const(s, s);
 
        return s;
@@ -1287,7 +1293,6 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const
        return _talloc_zero(ctx, el_size * count, name);
 }
 
-
 /*
   realloc an array, checking for integer overflow in the array size
 */