[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tip-f787d9519fb10411f2948f5b9957a1669879ba84@git.kernel.org>
Date: Tue, 13 Nov 2012 22:28:09 -0800
From: tip-bot for Namhyung Kim <namhyung@...nel.org>
To: linux-tip-commits@...r.kernel.org
Cc: acme@...hat.com, linux-kernel@...r.kernel.org, hpa@...or.com,
mingo@...nel.org, drjones@...hat.com, tglx@...utronix.de,
namhyung@...nel.org
Subject: [tip:perf/urgent] perf tools: Fix strbuf_addf()
when the buffer needs to grow
Commit-ID: f787d9519fb10411f2948f5b9957a1669879ba84
Gitweb: http://git.kernel.org/tip/f787d9519fb10411f2948f5b9957a1669879ba84
Author: Namhyung Kim <namhyung@...nel.org>
AuthorDate: Tue, 23 Oct 2012 22:44:50 +0900
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Tue, 30 Oct 2012 10:32:56 -0200
perf tools: Fix strbuf_addf() when the buffer needs to grow
This was found during chasing down the header output regression. The
strbuf_addf() was checking buffer length with a result of vscnprintf()
which cannot be greater than that of strbuf_avail().
Since numa topology and pmu mapping info in header were converted to use
strbuf, it sometimes caused uninteresting behaviors with the broken
strbuf.
Fix it by using vsnprintf() which returns desired output string length
regardless of the available buffer size and grow the buffer if needed.
Reported-by: Andrew Jones <drjones@...hat.com>
Tested-by: Andrew Jones <drjones@...hat.com>
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
Cc: Andrew Jones <drjones@...hat.com>
Link: http://lkml.kernel.org/r/1350999890-6920-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/strbuf.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 2eeb51b..cfa9068 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -90,17 +90,17 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
if (!strbuf_avail(sb))
strbuf_grow(sb, 64);
va_start(ap, fmt);
- len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
+ len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
va_end(ap);
if (len < 0)
- die("your vscnprintf is broken");
+ die("your vsnprintf is broken");
if (len > strbuf_avail(sb)) {
strbuf_grow(sb, len);
va_start(ap, fmt);
- len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
+ len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
va_end(ap);
if (len > strbuf_avail(sb)) {
- die("this should not happen, your snprintf is broken");
+ die("this should not happen, your vsnprintf is broken");
}
}
strbuf_setlen(sb, sb->len + len);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists