sbuf_vprintf: ap is not consistent at second call of kvsnprintf. Use a copy
authorMihai Carabas <mihai.carabas@gmail.com>
Sun, 1 Jul 2012 19:18:25 +0000 (22:18 +0300)
committerSascha Wildner <saw@online.de>
Thu, 5 Jul 2012 20:53:02 +0000 (22:53 +0200)
sys/kern/subr_sbuf.c

index d834dff..12bc266 100644 (file)
@@ -401,7 +401,7 @@ int
 sbuf_vprintf(struct sbuf *s, const char *fmt, __va_list ap)
 {
        int len;
-
+       __va_list ap_copy;
        assert_sbuf_integrity(s);
        assert_sbuf_state(s, 0);
 
@@ -412,8 +412,10 @@ sbuf_vprintf(struct sbuf *s, const char *fmt, __va_list ap)
                return (-1);
 
        do {
+               __va_copy(ap_copy, ap);
                len = kvsnprintf(&s->s_buf[s->s_len], SBUF_FREESPACE(s) + 1,
-                                fmt, ap);
+                                fmt, ap_copy);
+               __va_end(ap_copy);
        } while (len > SBUF_FREESPACE(s) &&
            sbuf_extend(s, len - SBUF_FREESPACE(s)) == 0);