mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-11-08 07:42:41 +00:00
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 <namhyung@kernel.org> Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Link: https://lore.kernel.org/r/20221123180208.2068936-5-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
8e55ae24c0
commit
a7ec1dd2d7
@ -1073,23 +1073,23 @@ static void print_metric_headers(struct perf_stat_config *config,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_interval(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)
|
if (config->iostat_run)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (config->csv_output)
|
if (config->csv_output)
|
||||||
sprintf(prefix, "%lu.%09lu%s", (unsigned long) ts->tv_sec,
|
scnprintf(prefix, len, "%lu.%09lu%s",
|
||||||
ts->tv_nsec, config->csv_sep);
|
(unsigned long) ts->tv_sec, ts->tv_nsec, config->csv_sep);
|
||||||
else if (!config->json_output)
|
else if (!config->json_output)
|
||||||
sprintf(prefix, "%6lu.%09lu ", (unsigned long) ts->tv_sec,
|
scnprintf(prefix, len, "%6lu.%09lu ",
|
||||||
ts->tv_nsec);
|
(unsigned long) ts->tv_sec, ts->tv_nsec);
|
||||||
else if (!config->metric_only)
|
else if (!config->metric_only)
|
||||||
sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
|
scnprintf(prefix, len, "{\"interval\" : %lu.%09lu, ",
|
||||||
ts->tv_sec, ts->tv_nsec);
|
(unsigned long) ts->tv_sec, ts->tv_nsec);
|
||||||
else
|
else
|
||||||
sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long)
|
scnprintf(prefix, len, "{\"interval\" : %lu.%09lu}",
|
||||||
ts->tv_sec, ts->tv_nsec);
|
(unsigned long) ts->tv_sec, ts->tv_nsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_header_interval_std(struct perf_stat_config *config,
|
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) {
|
if (interval) {
|
||||||
prefix = buf;
|
prefix = buf;
|
||||||
prepare_interval(config, prefix, ts);
|
prepare_interval(config, buf, sizeof(buf), ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_header(config, _target, evlist, argc, argv);
|
print_header(config, _target, evlist, argc, argv);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user