Skip to content

Commit c4cc180

Browse files
seehearfeelqmonnet
authored andcommitted
bpftool: Silence build warning about calloc()
There exists the following warning when building bpftool: CC prog.o prog.c: In function ‘profile_open_perf_events’: prog.c:2301:24: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args] 2301 | sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric); | ^~~ prog.c:2301:24: note: earlier argument should specify number of elements, later size of each element Tested with the latest upstream GCC which contains a new warning option -Wcalloc-transposed-args. The first argument to calloc is documented to be number of elements in array, while the second argument is size of each element, just switch the first and second arguments of calloc() to silence the build warning, compile tested only. Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command") Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 184ca6d commit c4cc180

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/prog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ static int profile_open_perf_events(struct profiler_bpf *obj)
22982298
int map_fd;
22992299

23002300
profile_perf_events = calloc(
2301-
sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric);
2301+
obj->rodata->num_cpu * obj->rodata->num_metric, sizeof(int));
23022302
if (!profile_perf_events) {
23032303
p_err("failed to allocate memory for perf_event array: %s",
23042304
strerror(errno));

0 commit comments

Comments
 (0)