r21174: many thanks to Paul Wayper for pointing out that C99 requires a
authorAndrew Tridgell <tridge@samba.org>
Tue, 6 Feb 2007 05:26:25 +0000 (05:26 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:44:42 +0000 (14:44 -0500)
matching va_end() for each va_copy(). This doesn't matter for most
architectures, but there could be some obscure ones where it does
matter.

some of this should be ported to Samba3
(This used to be commit 21eb316473486cb6b73bb3ff9c5f3a44ecd57e4a)

source4/lib/replace/snprintf.c
source4/lib/talloc/talloc.c
source4/lib/util/dprintf.c
source4/lib/util/util_file.c
source4/lib/util/xfile.c

index b38d8dad34af66543946640439f364411fb401b6..9f8a7657e525b7653b7f6148441c83bc3255f6c5 100644 (file)
@@ -742,6 +742,8 @@ static int dopr(char *buffer, size_t maxlen, const char *format, va_list args_in
        ret = currlen;
 
 done:
+       va_end(args);
+
        while (chunks) {
                cnk = chunks->next;
                free(chunks);
@@ -1260,16 +1262,16 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
        va_list ap2;
 
        VA_COPY(ap2, ap);
-       
        ret = vsnprintf(NULL, 0, format, ap2);
+       va_end(ap2);
        if (ret <= 0) return ret;
 
        (*ptr) = (char *)malloc(ret+1);
        if (!*ptr) return -1;
 
        VA_COPY(ap2, ap);
-
        ret = vsnprintf(*ptr, ret+1, format, ap2);
+       va_end(ap2);
 
        return ret;
 }
index 15a44bd0d99298661fe70a7f9957177507dc99ac..028b44a8c72e08f48f7fad0abfe1d4034e288633 100644 (file)
@@ -1174,10 +1174,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 +1186,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 +1228,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 +1248,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;
index 62dc2a227a168f13fb04019d04828ca11d3b13a9..79b90ec3e1b2eac24206b887eda35d8ea1e44a74 100644 (file)
@@ -39,8 +39,8 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU
 
        /* do any message translations */
        va_copy(ap2, ap);
-
        ret = vasprintf(&p, format, ap2);
+       va_end(ap2);
 
        if (ret <= 0) return ret;
 
index 887efb98364bea526e60cab8fbba51d056b886ad..3c44351c5026b048c0fbe2668980bf401f7871c9 100644 (file)
@@ -364,8 +364,8 @@ _PUBLIC_ int vfdprintf(int fd, const char *format, va_list ap) _PRINTF_ATTRIBUTE
        va_list ap2;
 
        va_copy(ap2, ap);
-
        len = vasprintf(&p, format, ap2);
+       va_end(ap2);
        if (len <= 0) return len;
        ret = write(fd, p, len);
        SAFE_FREE(p);
index 1cf77a3220bbc0f3a2e9841b8d3f0101d38cf4c7..870cd4c13676f05bd9ee22eebcf71cf395c0acca 100644 (file)
@@ -203,8 +203,8 @@ size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f)
        va_list ap2;
 
        va_copy(ap2, ap);
-
        len = vasprintf(&p, format, ap2);
+       va_end(ap2);
        if (len <= 0) return len;
        ret = x_fwrite(p, 1, len, f);
        SAFE_FREE(p);