Skip to content

Commit

Permalink
Fix transposed calloc() arguments
Browse files Browse the repository at this point in the history
Calls to calloc() are supposed to have the number of elements as the first
argument, but we erroneously transposed the arguments in a couple of places. It
seems GCC 14 has started to warn about this, which exposed this as build
breakage.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
  • Loading branch information
tohojo committed Jan 18, 2024
1 parent a7b0903 commit b184d10
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/util/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static int handle_ifname_multi(char *optarg, void *tgt, __unused struct prog_opt
if (ifindex < 0)
return ifindex;

iface = calloc(sizeof(*iface), 1);
iface = calloc(1, sizeof(*iface));
if (!iface)
return -ENOMEM;

Expand Down
6 changes: 3 additions & 3 deletions lib/util/xpcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static bool pcapng_write_shb(struct xpcapng_dumper *pd, const char *comment,
shb_length += sizeof(uint32_t);

/* Allocate the SHB and fill it. */
shb = calloc(shb_length, 1);
shb = calloc(1, shb_length);
if (shb == NULL) {
errno = ENOMEM;
return false;
Expand Down Expand Up @@ -318,7 +318,7 @@ static bool pcapng_write_idb(struct xpcapng_dumper *pd, const char *name,
idb_length += sizeof(uint32_t);

/* Allocate the IDB and fill it. */
idb = calloc(idb_length, 1);
idb = calloc(1, idb_length);
if (idb == NULL) {
errno = ENOMEM;
return false;
Expand Down Expand Up @@ -549,7 +549,7 @@ struct xpcapng_dumper *xpcapng_dump_open(const char *file,
goto error_exit;
}

pd = calloc(sizeof(*pd), 1);
pd = calloc(1, sizeof(*pd));
if (pd == NULL) {
errno = ENOMEM;
goto error_exit;
Expand Down
4 changes: 2 additions & 2 deletions xdp-trafficgen/xdp-trafficgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ static int create_runners(pthread_t **runner_threads, struct thread_config **thr
pthread_t *threads;
int i, err;

threads = calloc(sizeof(pthread_t), num_threads);
threads = calloc(num_threads, sizeof(pthread_t));
if (!threads) {
pr_warn("Couldn't allocate memory\n");
return -ENOMEM;
}

t = calloc(sizeof(struct thread_config), num_threads);
t = calloc(num_threads, sizeof(struct thread_config));
if (!t) {
pr_warn("Couldn't allocate memory\n");
free(threads);
Expand Down

0 comments on commit b184d10

Please sign in to comment.