Looking through some static analysis of lipbfm I found minor issues in the
format strings of some of the perf examples. The attached patch addresses
those.
-Will
From 2b39641e784c05044489b5236cf5bff203cc1109 Mon Sep 17 00:00:00 2001
From: William Cohen <wco...@redhat.com>
Date: Fri, 30 Jun 2023 13:29:57 -0400
Subject: [PATCH] Remove extraneous "'" from fprintf statements
Static analysis of libpfm found a number of places where "'" was in
the format specifier. Those have to removed to eliminate errors like
the following example:
Error: PRINTF_ARGS (CWE-475): [#def97]
libpfm-4.13.0/perf_examples/perf_util.c:463: format_error: Flag "'" not applicable to conversion specifier in "%'lu". [Note: The source code implementation of the function has been overridden by a builtin model.]
# 461| }
# 462|
# 463|-> fprintf(fp, "TIME:%'"PRIu64" ", val64);
# 464| sz -= sizeof(val64);
# 465| }
---
perf_examples/perf_util.c | 18 +++++++++---------
perf_examples/self.c | 2 +-
perf_examples/self_basic.c | 2 +-
perf_examples/syst_count.c | 2 +-
perf_examples/task.c | 4 ++--
perf_examples/task_cpu.c | 4 ++--
6 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/perf_examples/perf_util.c b/perf_examples/perf_util.c
index a97ed77..2921a45 100644
--- a/perf_examples/perf_util.c
+++ b/perf_examples/perf_util.c
@@ -460,7 +460,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
return -1;
}
- fprintf(fp, "TIME:%'"PRIu64" ", val64);
+ fprintf(fp, "TIME:%"PRIu64" ", val64);
sz -= sizeof(val64);
}
@@ -513,7 +513,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
warnx( "cannot read period");
return -1;
}
- fprintf(fp, "PERIOD:%'"PRIu64" ", val64);
+ fprintf(fp, "PERIOD:%"PRIu64" ", val64);
sz -= sizeof(val64);
}
@@ -566,7 +566,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
sz -= sizeof(time_running);
}
- fprintf(fp, "ENA=%'"PRIu64" RUN=%'"PRIu64" NR=%"PRIu64"\n", time_enabled, time_running, nr);
+ fprintf(fp, "ENA=%"PRIu64" RUN=%"PRIu64" NR=%"PRIu64"\n", time_enabled, time_running, nr);
values[1] = time_enabled;
values[2] = time_running;
@@ -597,7 +597,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
values[0] = grp.value;
grp.value = perf_scale(values);
- fprintf(fp, "\t%'"PRIu64" %s (%"PRIu64"%s)\n",
+ fprintf(fp, "\t%"PRIu64" %s (%"PRIu64"%s)\n",
grp.value, str,
grp.id,
time_running != time_enabled ? ", scaled":"");
@@ -641,14 +641,14 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
sz -= sizeof(val64);
}
- fprintf(fp, "ENA=%'"PRIu64" RUN=%'"PRIu64"\n", time_enabled, time_running);
+ fprintf(fp, "ENA=%"PRIu64" RUN=%"PRIu64"\n", time_enabled, time_running);
values[0] = val64;
values[1] = time_enabled;
values[2] = time_running;
val64 = perf_scale(values);
- fprintf(fp, "\t%'"PRIu64" %s %s\n",
+ fprintf(fp, "\t%"PRIu64" %s %s\n",
val64, fds[0].name,
time_running != time_enabled ? ", scaled":"");
}
@@ -705,7 +705,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
warnx( "cannot read weight");
return -1;
}
- fprintf(fp, "WEIGHT:%'"PRIu64" ", val64);
+ fprintf(fp, "WEIGHT:%"PRIu64" ", val64);
sz -= sizeof(val64);
}
@@ -715,7 +715,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
warnx( "cannot read data src");
return -1;
}
- fprintf(fp, "DATA_SRC:%'"PRIu64" ", val64);
+ fprintf(fp, "DATA_SRC:%"PRIu64" ", val64);
sz -= sizeof(val64);
}
if (type & PERF_SAMPLE_TRANSACTION) {
@@ -724,7 +724,7 @@ perf_display_sample(perf_event_desc_t *fds, int num_fds, int idx, struct perf_ev
warnx( "cannot read txn");
return -1;
}
- fprintf(fp, "TXN:%'"PRIu64" ", val64);
+ fprintf(fp, "TXN:%"PRIu64" ", val64);
sz -= sizeof(val64);
}
diff --git a/perf_examples/self.c b/perf_examples/self.c
index 7e9aa23..24a145d 100644
--- a/perf_examples/self.c
+++ b/perf_examples/self.c
@@ -95,7 +95,7 @@ print_counts(perf_event_desc_t *fds, int num_fds, const char *msg)
val = perf_scale(values);
ratio = perf_scale_ratio(values);
- printf("%s %'20"PRIu64" %s (%.2f%% scaling, raw=%'"PRIu64", ena=%'"PRIu64", run=%'"PRIu64")\n",
+ printf("%s %'20"PRIu64" %s (%.2f%% scaling, raw=%"PRIu64", ena=%"PRIu64", run=%"PRIu64")\n",
msg,
val,
fds[i].name,
diff --git a/perf_examples/self_basic.c b/perf_examples/self_basic.c
index d3c8ef7..9b793d3 100644
--- a/perf_examples/self_basic.c
+++ b/perf_examples/self_basic.c
@@ -135,7 +135,7 @@ main(int argc, char **argv)
if (values[2])
count = (uint64_t)((double)values[0] * values[1]/values[2]);
- printf("count=%'"PRIu64"\n", count);
+ printf("count=%"PRIu64"\n", count);
close(fd);
diff --git a/perf_examples/syst_count.c b/perf_examples/syst_count.c
index 31666e1..5ec3228 100644
--- a/perf_examples/syst_count.c
+++ b/perf_examples/syst_count.c
@@ -268,7 +268,7 @@ void read_cpu(int c)
val = perf_scale(fds[j].values);
ratio = perf_scale_ratio(fds[j].values);
- printf("CPU%-3d G%-2d %'20"PRIu64" %'20"PRIu64" %s (scaling %.2f%%, ena=%'"PRIu64", run=%'"PRIu64") %s\n",
+ printf("CPU%-3d G%-2d %20"PRIu64" %20"PRIu64" %s (scaling %.2f%%, ena=%"PRIu64", run=%"PRIu64") %s\n",
c,
i,
val,
diff --git a/perf_examples/task.c b/perf_examples/task.c
index 35f0915..03b45ca 100644
--- a/perf_examples/task.c
+++ b/perf_examples/task.c
@@ -150,7 +150,7 @@ print_counts(perf_event_desc_t *fds, int num)
putchar('\n');
if (options.print)
- printf("%'20"PRIu64" %'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n",
+ printf("%20"PRIu64" %20"PRIu64" %s (%.2f%% scaling, ena=%"PRIu64", run=%"PRIu64")\n",
val,
delta,
fds[i].name,
@@ -158,7 +158,7 @@ print_counts(perf_event_desc_t *fds, int num)
fds[i].values[1],
fds[i].values[2]);
else
- printf("%'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n",
+ printf("%20"PRIu64" %s (%.2f%% scaling, ena=%"PRIu64", run=%"PRIu64")\n",
val,
fds[i].name,
(1.0-ratio)*100.0,
diff --git a/perf_examples/task_cpu.c b/perf_examples/task_cpu.c
index d7ee9c3..571433c 100644
--- a/perf_examples/task_cpu.c
+++ b/perf_examples/task_cpu.c
@@ -152,7 +152,7 @@ print_counts(perf_event_desc_t *fds, int num, int cpu)
putchar('\n');
if (options.print)
- printf("CPU%-2d %'20"PRIu64" %'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n",
+ printf("CPU%-2d %20"PRIu64" %20"PRIu64" %s (%.2f%% scaling, ena=%"PRIu64", run=%"PRIu64")\n",
cpu,
val,
delta,
@@ -161,7 +161,7 @@ print_counts(perf_event_desc_t *fds, int num, int cpu)
fds[i].values[1],
fds[i].values[2]);
else
- printf("CPU%-2d %'20"PRIu64" %s (%.2f%% scaling, ena=%'"PRIu64", run=%'"PRIu64")\n",
+ printf("CPU%-2d %20"PRIu64" %s (%.2f%% scaling, ena=%"PRIu64", run=%"PRIu64")\n",
cpu,
val,
fds[i].name,
--
2.41.0
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel