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 <erik.faye-lund@collabora.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
macos/master
Erik Faye-Lund 6 years ago committed by Dave Airlie
parent 6c530b502d
commit c5e7173212
  1. 6
      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);
}

Loading…
Cancel
Save