Commit af414f34 authored by Sanskriti Sharma's avatar Sanskriti Sharma Committed by Greg Kroah-Hartman

perf strbuf: Match va_{add,copy} with va_end

[ Upstream commit ce49d8436cffa9b7a6a5f110879d53e89dbc6746 ]

Ensure that all code paths in strbuf_addv() call va_end() on the
ap_saved copy that was made.

Fixes the following coverity complaint:

  Error: VARARGS (CWE-237): [#def683]
  tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called
  for "ap_saved".
Signed-off-by: default avatarSanskriti Sharma <>
Reviewed-by: default avatarJiri Olsa <>
Cc: Joe Lawrence <>
Link: default avatarArnaldo Carvalho de Melo <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 0af42d67
......@@ -105,19 +105,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
va_copy(ap_saved, ap);
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
if (len < 0)
if (len < 0) {
return len;
if (len > strbuf_avail(sb)) {
ret = strbuf_grow(sb, len);
if (ret)
if (ret) {
return ret;
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is broken");
return -EINVAL;
return strbuf_setlen(sb, sb->len + len);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment