Commit 2543947c authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim

perf stat: Avoid metric-only segv

Cycles is recognized as part of a hard coded metric in stat-shadow.c,
it may call print_metric_only with a NULL fmt string leading to a
segfault. Handle the NULL fmt explicitly.

Fixes: 088519f3 ("perf stat: Move the display functions to stat-display.c")
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: James Clark <james.clark@arm.com>
Cc: Kaige Ye <ye@kaige.org>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240209204947.3873294-4-irogers@google.com
parent 6dd76680
...@@ -571,7 +571,7 @@ static void print_metric_only(struct perf_stat_config *config, ...@@ -571,7 +571,7 @@ static void print_metric_only(struct perf_stat_config *config,
if (color) if (color)
mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1; mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
color_snprintf(str, sizeof(str), color ?: "", fmt, val); color_snprintf(str, sizeof(str), color ?: "", fmt ?: "", val);
fprintf(out, "%*s ", mlen, str); fprintf(out, "%*s ", mlen, str);
os->first = false; os->first = false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment