From: tip-bot for Namhyung Kim <namhyung@kernel.org>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com,
mingo@kernel.org, drjones@redhat.com, tglx@linutronix.de,
namhyung@kernel.org
Subject: [tip:perf/urgent] perf tools: Fix strbuf_addf() when the buffer needs to grow
Date: Tue, 13 Nov 2012 22:28:09 -0800 [thread overview]
Message-ID: <tip-f787d9519fb10411f2948f5b9957a1669879ba84@git.kernel.org> (raw)
In-Reply-To: <1350999890-6920-2-git-send-email-namhyung@kernel.org>
Commit-ID: f787d9519fb10411f2948f5b9957a1669879ba84
Gitweb: http://git.kernel.org/tip/f787d9519fb10411f2948f5b9957a1669879ba84
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Tue, 23 Oct 2012 22:44:50 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.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@redhat.com>
Tested-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andrew Jones <drjones@redhat.com>
Link: http://lkml.kernel.org/r/1350999890-6920-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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);
next prev parent reply other threads:[~2012-11-14 6:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-22 13:11 perf: header: Regression Andrew Jones
2012-10-23 2:07 ` Namhyung Kim
2012-10-23 7:27 ` Andrew Jones
2012-10-23 13:44 ` [PATCH 1/2] perf header: Fix numa topology printing Namhyung Kim
2012-10-23 13:44 ` [PATCH 2/2] perf tools: Fix strbuf_addf() when the buffer needs to grow Namhyung Kim
2012-10-24 7:49 ` Andrew Jones
2012-11-14 6:28 ` tip-bot for Namhyung Kim [this message]
2012-10-23 14:12 ` [PATCH 1/2] perf header: Fix numa topology printing Andrew Jones
2012-10-24 7:00 ` Namhyung Kim
2012-10-24 7:49 ` Andrew Jones
2012-10-29 15:17 ` Namhyung Kim
2012-11-14 6:27 ` [tip:perf/urgent] " tip-bot for Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-f787d9519fb10411f2948f5b9957a1669879ba84@git.kernel.org \
--to=namhyung@kernel.org \
--cc=acme@redhat.com \
--cc=drjones@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).