Skip to content

Commit

Permalink
graph: Fix a compiler warning
Browse files Browse the repository at this point in the history
The calloc() takes the first argument for the number of element, not the
size of the element.  Recent compilers warn about it like below:

    CC       utils/graph.ot
  In file included from /home/namhyung/project/uftrace/utils/symbol.h:18,
                   from /home/namhyung/project/uftrace/uftrace.h:14,
                   from /home/namhyung/project/uftrace/utils/graph.h:7,
                   from /home/namhyung/project/uftrace/utils/graph.c:1:
  /home/namhyung/project/uftrace/utils/graph.c: In function ‘setup_fstack_and_graph’:
  /home/namhyung/project/uftrace/utils/graph.c:300:41: warning: ‘calloc’ sizes specified with ‘sizeof’
         in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
    300 |         task.func_stack = xcalloc(sizeof(*task.func_stack), len);
        |                                         ^
  /home/namhyung/project/uftrace/utils/utils.h:202:38: note: in definition of macro ‘xcalloc’
    202 |                 void *__ptr = calloc(n, sz);                                                       \
        |                                      ^
  /home/namhyung/project/uftrace/utils/graph.c:300:41: note: earlier argument should specify number of
         elements, later size of each element
    300 |         task.func_stack = xcalloc(sizeof(*task.func_stack), len);
        |                                         ^
  /home/namhyung/project/uftrace/utils/utils.h:202:38: note: in definition of macro ‘xcalloc’
    202 |                 void *__ptr = calloc(n, sz);                                                       \
        |                                      ^

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
  • Loading branch information
namhyung committed Nov 29, 2024
1 parent e324d23 commit b4a8c4b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static void setup_fstack_and_graph(struct uftrace_graph *graph, struct test_data
tg->new_sess = true;

/* TODO: de-couple graph from fstack */
task.func_stack = xcalloc(sizeof(*task.func_stack), len);
task.func_stack = xcalloc(len, sizeof(*task.func_stack));

for (i = 0; i < len; i++) {
struct uftrace_fstack *fstack = NULL;
Expand Down

0 comments on commit b4a8c4b

Please sign in to comment.