aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/strbuf.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-03-14 11:29:29 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-03-14 11:36:19 -0400
commite7f01d1e3d8d501deb8abeaa269d5d48a703b8b0 (patch)
tree2746465309fd16392ed7c6265dea53366c6e52c7 /tools/perf/util/strbuf.c
parentb832796caa1fda8516464a003c8c7cc547bc20c2 (diff)
perf tools: Use scnprintf where applicable
Several places were expecting that the value returned was the number of characters printed, not what would be printed if there was space. Fix it by using the scnprintf and vscnprintf variants we inherited from the kernel sources. Some corner cases where the number of printed characters were not accounted were fixed too. Reported-by: Anton Blanchard <anton@samba.org> Cc: Anton Blanchard <anton@samba.org> Cc: Eric B Munson <emunson@mgebm.net> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Yanmin Zhang <yanmin_zhang@linux.intel.com> Cc: stable@kernel.org Link: http://lkml.kernel.org/n/tip-kwxo2eh29cxmd8ilixi2005x@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/strbuf.c')
-rw-r--r--tools/perf/util/strbuf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 92e068517c1a..2eeb51baf077 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -1,4 +1,5 @@
1#include "cache.h" 1#include "cache.h"
2#include <linux/kernel.h>
2 3
3int prefixcmp(const char *str, const char *prefix) 4int prefixcmp(const char *str, const char *prefix)
4{ 5{
@@ -89,14 +90,14 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
89 if (!strbuf_avail(sb)) 90 if (!strbuf_avail(sb))
90 strbuf_grow(sb, 64); 91 strbuf_grow(sb, 64);
91 va_start(ap, fmt); 92 va_start(ap, fmt);
92 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 93 len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
93 va_end(ap); 94 va_end(ap);
94 if (len < 0) 95 if (len < 0)
95 die("your vsnprintf is broken"); 96 die("your vscnprintf is broken");
96 if (len > strbuf_avail(sb)) { 97 if (len > strbuf_avail(sb)) {
97 strbuf_grow(sb, len); 98 strbuf_grow(sb, len);
98 va_start(ap, fmt); 99 va_start(ap, fmt);
99 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 100 len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
100 va_end(ap); 101 va_end(ap);
101 if (len > strbuf_avail(sb)) { 102 if (len > strbuf_avail(sb)) {
102 die("this should not happen, your snprintf is broken"); 103 die("this should not happen, your snprintf is broken");