aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/stat-display.c
diff options
context:
space:
mode:
authorNamhyung Kim <[email protected]>2022-11-23 18:01:57 +0000
committerArnaldo Carvalho de Melo <[email protected]>2022-11-24 12:37:08 +0000
commita7ec1dd2d744208ca814ebde8c97f94e041625ef (patch)
tree60e1fb012cbfc34fa441990f7cbe6a3034300cab /tools/perf/util/stat-display.c
parentperf stat: Do not align time prefix in CSV output (diff)
downloadkernel-a7ec1dd2d744208ca814ebde8c97f94e041625ef.tar.gz
kernel-a7ec1dd2d744208ca814ebde8c97f94e041625ef.zip
perf stat: Use scnprintf() in prepare_interval()
It should not use sprintf() anymore. Let's pass the buffer size and use the safer scnprintf() instead. Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Athira Jajeev <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Xing Zhengjun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/perf/util/stat-display.c')
-rw-r--r--tools/perf/util/stat-display.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 15c88b9b5aa3..744b7a40f59a 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -1073,23 +1073,23 @@ static void print_metric_headers(struct perf_stat_config *config,
}
static void prepare_interval(struct perf_stat_config *config,
- char *prefix, struct timespec *ts)
+ char *prefix, size_t len, struct timespec *ts)
{
if (config->iostat_run)
return;
if (config->csv_output)
- sprintf(prefix, "%lu.%09lu%s", (unsigned long) ts->tv_sec,
- ts->tv_nsec, config->csv_sep);
+ scnprintf(prefix, len, "%lu.%09lu%s",
+ (unsigned long) ts->tv_sec, ts->tv_nsec, config->csv_sep);
else if (!config->json_output)
- sprintf(prefix, "%6lu.%09lu ", (unsigned long) ts->tv_sec,
- ts->tv_nsec);
+ scnprintf(prefix, len, "%6lu.%09lu ",
+ (unsigned long) ts->tv_sec, ts->tv_nsec);
else if (!config->metric_only)
- sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
- ts->tv_sec, ts->tv_nsec);
+ scnprintf(prefix, len, "{\"interval\" : %lu.%09lu, ",
+ (unsigned long) ts->tv_sec, ts->tv_nsec);
else
- sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long)
- ts->tv_sec, ts->tv_nsec);
+ scnprintf(prefix, len, "{\"interval\" : %lu.%09lu}",
+ (unsigned long) ts->tv_sec, ts->tv_nsec);
}
static void print_header_interval_std(struct perf_stat_config *config,
@@ -1390,7 +1390,7 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
if (interval) {
prefix = buf;
- prepare_interval(config, prefix, ts);
+ prepare_interval(config, buf, sizeof(buf), ts);
}
print_header(config, _target, evlist, argc, argv);