aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2012-10-23 09:44:50 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-30 08:32:56 -0400
commitf787d9519fb10411f2948f5b9957a1669879ba84 (patch)
tree844cabbae20e511912261ca2ad3ece33852e5bd3 /tools
parent1234471e2d11e4ee47f6de452dd8b8aeb09b45de (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/strbuf.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 2eeb51baf077..cfa906882e2c 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, ...)
90 if (!strbuf_avail(sb)) 90 if (!strbuf_avail(sb))
91 strbuf_grow(sb, 64); 91 strbuf_grow(sb, 64);
92 va_start(ap, fmt); 92 va_start(ap, fmt);
93 len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 93 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
94 va_end(ap); 94 va_end(ap);
95 if (len < 0) 95 if (len < 0)
96 die("your vscnprintf is broken"); 96 die("your vsnprintf is broken");
97 if (len > strbuf_avail(sb)) { 97 if (len > strbuf_avail(sb)) {
98 strbuf_grow(sb, len); 98 strbuf_grow(sb, len);
99 va_start(ap, fmt); 99 va_start(ap, fmt);
100 len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 100 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
101 va_end(ap); 101 va_end(ap);
102 if (len > strbuf_avail(sb)) { 102 if (len > strbuf_avail(sb)) {
103 die("this should not happen, your snprintf is broken"); 103 die("this should not happen, your vsnprintf is broken");
104 } 104 }
105 } 105 }
106 strbuf_setlen(sb, sb->len + len); 106 strbuf_setlen(sb, sb->len + len);