From c5e7173212aa078e18341e0b63ce5a8e14f0b610 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 9 Jan 2019 13:52:44 +0100 Subject: [PATCH] strbuf: copy varargs-list in case of reuse It's not legal to reuse the varargs list without taking a copy, so let's do that before we use it. Signed-off-by: Erik Faye-Lund Reviewed-by: Dave Airlie --- src/vrend_strbuf.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vrend_strbuf.h b/src/vrend_strbuf.h index 5d023f2..ea91ed4 100644 --- a/src/vrend_strbuf.h +++ b/src/vrend_strbuf.h @@ -124,6 +124,10 @@ static inline void strbuf_append(struct vrend_strbuf *sb, const char *addstr) static inline void strbuf_vappendf(struct vrend_strbuf *sb, const char *fmt, va_list ap) { char buf[512]; + + va_list cp; + va_copy(cp, ap); + int len = vsnprintf(buf, sizeof(buf), fmt, ap); if (len < (int)sizeof(buf)) { strbuf_append(sb, buf); @@ -135,7 +139,7 @@ static inline void strbuf_vappendf(struct vrend_strbuf *sb, const char *fmt, va_ strbuf_set_error(sb); return; } - vsnprintf(tmp, len, fmt, ap); + vsnprintf(tmp, len, fmt, cp); strbuf_append(sb, tmp); free(tmp); }