src: Eliminate warnings with -Wcalloc-transposed-args
Phil Sutter
reviewerPATCH 1/1 src: Eliminate warnings with -Wcalloc-transposed-args
calloc() expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).
--- src/channel.c | 4 ++-- src/channel_mcast.c | 2 +- src/channel_tcp.c | 2 +- src/channel_udp.c | 2 +- src/fds.c | 4 ++-- src/filter.c | 2 +- src/multichannel.c | 2 +- src/origin.c | 2 +- src/process.c | 2 +- src/queue.c | 2 +- src/tcp.c | 4 ++-- src/udp.c | 4 ++-- src/vector.c | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-)
src/channel.c +2 -2
@@ -56,7 +56,7 @@ channel_buffer_open(int mtu, int headersiz) {struct channel_buffer *b; - b =calloc (sizeof (struct channel_buffer ),1 ); + b =calloc (1 ,sizeof (struct channel_buffer ));if (b ==NULL )return NULL ;
@@ -94,7 +94,7 @@ channel_open(struct channel_conf *cfg)if (cfg->channel_flags >=CHANNEL_F_MAX )return NULL ; - c =calloc (sizeof (struct channel ),1 ); + c =calloc (1 ,sizeof (struct channel ));if (c ==NULL )return NULL ;
src/channel_mcast.c +1 -1
@@ -19,7 +19,7 @@ static voidstruct mcast_channel *m;struct mcast_conf *c = conf; - m =calloc (sizeof (struct mcast_channel ),1 ); + m =calloc (1 ,sizeof (struct mcast_channel ));if (m ==NULL )return NULL ;
src/channel_tcp.c +1 -1
@@ -21,7 +21,7 @@ static voidstruct tcp_channel *m;struct tcp_conf *c = conf; - m =calloc (sizeof (struct tcp_channel ),1 ); + m =calloc (1 ,sizeof (struct tcp_channel ));if (m ==NULL )return NULL ;
src/channel_udp.c +1 -1
@@ -19,7 +19,7 @@ static voidstruct udp_channel *m;struct udp_conf *c = conf; - m =calloc (sizeof (struct udp_channel ),1 ); + m =calloc (1 ,sizeof (struct udp_channel ));if (m ==NULL )return NULL ;
src/fds.c +2 -2
@@ -30,7 +30,7 @@ struct fds *create_fds(void) {struct fds *fds; - fds = (struct fds *)calloc (sizeof (struct fds ),1 ); + fds =calloc (1 ,sizeof (struct fds ));if (fds ==NULL )return NULL ;
@@ -60,7 +60,7 @@ int register_fd(int fd, void (*cb)(void *data), void *data, struct fds *fds)if (fd > fds->maxfd) fds->maxfd = fd; - item =calloc (sizeof (struct fds_item ),1 ); + item =calloc (1 ,sizeof (struct fds_item ));if (item ==NULL )return -1 ;
src/filter.c +1 -1
@@ -77,7 +77,7 @@ struct ct_filter *ct_filter_create(void)int i;struct ct_filter *filter; - filter =calloc (sizeof (struct ct_filter ),1 ); + filter =calloc (1 ,sizeof (struct ct_filter ));if (!filter)return NULL ;
src/multichannel.c +1 -1
@@ -21,7 +21,7 @@ multichannel_open(struct channel_conf *conf, int len)if (len <=0 || len >MULTICHANNEL_MAX )return NULL ; - m =calloc (sizeof (struct multichannel ),1 ); + m =calloc (1 ,sizeof (struct multichannel ));if (m ==NULL )return NULL ;
src/origin.c +1 -1
@@ -31,7 +31,7 @@ int origin_register(struct nfct_handle *h, int origin_type) {struct origin *nlp; - nlp =calloc (sizeof (struct origin ),1 ); + nlp =calloc (1 ,sizeof (struct origin ));if (nlp ==NULL )return -1 ;
src/process.c +1 -1
@@ -37,7 +37,7 @@ int fork_process_new(int type, int flags, void (*cb)(void *data), void *data) } } } - c =calloc (sizeof (struct child_process ),1 ); + c =calloc (1 ,sizeof (struct child_process ));if (c ==NULL )return -1 ;
src/queue.c +1 -1
@@ -33,7 +33,7 @@ queue_create(const char *name, int max_objects, unsigned int flags) {struct queue *b; - b =calloc (sizeof (struct queue ),1 ); + b =calloc (1 ,sizeof (struct queue ));if (b ==NULL )return NULL ;
src/tcp.c +2 -2
@@ -31,7 +31,7 @@ struct tcp_sock *tcp_server_create(struct tcp_conf *c)struct tcp_sock *m;socklen_t socklen =sizeof (int ); - m =calloc (sizeof (struct tcp_sock ),1 ); + m =calloc (1 ,sizeof (struct tcp_sock ));if (m ==NULL )return NULL ;
@@ -209,7 +209,7 @@ struct tcp_sock *tcp_client_create(struct tcp_conf *c) {struct tcp_sock *m; - m =calloc (sizeof (struct tcp_sock ),1 ); + m =calloc (1 ,sizeof (struct tcp_sock ));if (m ==NULL )return NULL ;
src/udp.c +2 -2
@@ -25,7 +25,7 @@ struct udp_sock *udp_server_create(struct udp_conf *conf)struct udp_sock *m;socklen_t socklen =sizeof (int ); - m =calloc (sizeof (struct udp_sock ),1 ); + m =calloc (1 ,sizeof (struct udp_sock ));if (m ==NULL )return NULL ;
@@ -97,7 +97,7 @@ struct udp_sock *udp_client_create(struct udp_conf *conf)struct udp_sock *m;socklen_t socklen =sizeof (int ); - m =calloc (sizeof (struct udp_sock ),1 ); + m =calloc (1 ,sizeof (struct udp_sock ));if (m ==NULL )return NULL ;
src/vector.c +1 -1
@@ -35,7 +35,7 @@ struct vector *vector_create(size_t size) {struct vector *v; - v =calloc (sizeof (struct vector ),1 ); + v =calloc (1 ,sizeof (struct vector ));if (v ==NULL )return NULL ;
Signature · 1 line
2.47.0
Quoted 3 lines · Phil Sutter
calloc()expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).
Phil Sutter
reviewerQuoted 5 lines · Phil Sutter
calloc()expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).Signed-off-by Phil Sutter <[email protected]>
Patch applied.
Pablo Neira Ayuso
maintainerQuoted 3 lines · Phil Sutter
calloc()expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).
BTW, will you add
-Wcalloc-transposed-args
to Makefile.am?
Thanks
Phil Sutter
reviewerQuoted 10 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter
calloc()expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).BTW, will you add
-Wcalloc-transposed-args
to Makefile.am?
The gcc-14.2.1_p20240921 here seems to have this enabled by default. I did not pass any special configure or make options.
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 6 lines · Phil Sutter
Quoted 5 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter
calloc()expects the number of elements in the first parameter, not the second. Swap them and while at it drop one pointless cast (the function returns a void pointer anyway).
Quoted 8 lines
Quoted 5 lines
BTW, will you add
-Wcalloc-transposed-args
to Makefile.am?
The gcc-14.2.1_p20240921 here seems to have this enabled by default. I did not pass any special configure or make options.
I was expecting something like this, thanks for confirming.