Skip to content

Commit 11a64a0

Browse files
bwhacksacmel
authored andcommitted
perf pmu: Suppress potential format-truncation warning
Depending on which functions are inlined in util/pmu.c, the snprintf() calls in perf_pmu__parse_{scale,unit,per_pkg,snapshot}() might trigger a warning: util/pmu.c: In function 'pmu_aliases': util/pmu.c:178:31: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=] snprintf(path, PATH_MAX, "%s/%s.unit", dir, name); ^~ I found this when trying to build perf from Linux 3.16 with gcc 8. However I can reproduce the problem in mainline if I force __perf_pmu__new_alias() to be inlined. Suppress this by using scnprintf() as has been done elsewhere in perf. Signed-off-by: Ben Hutchings <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4787eff commit 11a64a0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/perf/util/pmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
145145
int fd, ret = -1;
146146
char path[PATH_MAX];
147147

148-
snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
148+
scnprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
149149

150150
fd = open(path, O_RDONLY);
151151
if (fd == -1)
@@ -175,7 +175,7 @@ static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *n
175175
ssize_t sret;
176176
int fd;
177177

178-
snprintf(path, PATH_MAX, "%s/%s.unit", dir, name);
178+
scnprintf(path, PATH_MAX, "%s/%s.unit", dir, name);
179179

180180
fd = open(path, O_RDONLY);
181181
if (fd == -1)
@@ -205,7 +205,7 @@ perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
205205
char path[PATH_MAX];
206206
int fd;
207207

208-
snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
208+
scnprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
209209

210210
fd = open(path, O_RDONLY);
211211
if (fd == -1)
@@ -223,7 +223,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
223223
char path[PATH_MAX];
224224
int fd;
225225

226-
snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
226+
scnprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
227227

228228
fd = open(path, O_RDONLY);
229229
if (fd == -1)

0 commit comments

Comments
 (0)