Skip to content

Commit

Permalink
uftrace: Align exact argument on calloc
Browse files Browse the repository at this point in the history
Align argument for calloc call in some code and macro in utils.h file.

Signed-off-by: Yunseong Kim <yskelg@gmail.com>
  • Loading branch information
yskelg authored and namhyung committed Jun 19, 2024
1 parent 3ad5f45 commit 804ae6b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmds/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ static int read_taskinfo(void *arg)
else if (!strncmp(&buf[9], "tids=", 5)) {
char *tids_str = &buf[14];
char *endp = tids_str;
int *tids = xcalloc(sizeof(*tids), info->nr_tid);
int *tids = xcalloc(info->nr_tid, sizeof(*tids));
int nr_tid = 0;

while (*endp != '\n') {
Expand Down
2 changes: 1 addition & 1 deletion libmcount/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void prepare_shmem_buffer(struct mcount_thread_data *mtdp)

shmem->nr_buf = 2;
shmem->max_buf = 2;
shmem->buffer = xcalloc(sizeof(*shmem->buffer), 2);
shmem->buffer = xcalloc(2, sizeof(*shmem->buffer));

for (idx = 0; idx < shmem->nr_buf; idx++) {
shmem->buffer[idx] = allocate_shmem_buffer(buf, sizeof(buf), tid, idx);
Expand Down
4 changes: 2 additions & 2 deletions libmcount/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static char **collect_uftrace_envp(void)
n++;
}

envp = xcalloc(sizeof(*envp), n + 2);
envp = xcalloc(n + 2, sizeof(*envp));

for (i = k = 0; i < ARRAY_SIZE(uftrace_env); i++) {
char *env_str;
Expand Down Expand Up @@ -232,7 +232,7 @@ static char **merge_envp(char *const *env1, char **env2)
n += count_envp(env1);
n += count_envp(env2);

envp = xcalloc(sizeof(*envp), n + 1);
envp = xcalloc(n + 1, sizeof(*envp));

n = 0;
for (i = 0; env1 && env1[i]; i++)
Expand Down
2 changes: 1 addition & 1 deletion utils/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ static int kernel_test_setup_handle(struct uftrace_kernel_reader *kernel,
int i;

handle->nr_tasks = NUM_TASK;
handle->tasks = xcalloc(sizeof(*handle->tasks), NUM_TASK);
handle->tasks = xcalloc(NUM_TASK, sizeof(*handle->tasks));

handle->time_range.start = handle->time_range.stop = 0;
handle->time_filter = 0;
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,16 @@ extern void setup_signal(void);

#define xzalloc(sz) \
({ \
void *__ptr = calloc(sz, 1); \
void *__ptr = calloc(1, sz); \
if (__ptr == NULL) { \
pr_err("xzalloc"); \
} \
__ptr; \
})

#define xcalloc(sz, n) \
#define xcalloc(n, sz) \
({ \
void *__ptr = calloc(sz, n); \
void *__ptr = calloc(n, sz); \
if (__ptr == NULL) { \
pr_err("xcalloc"); \
} \
Expand Down

0 comments on commit 804ae6b

Please sign in to comment.