From 9ab77e015dcb24eede6debe4e9e5d766fee2163a Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 9 Jan 2022 18:42:20 +0000 Subject: [PATCH] cleanup: Fix `calloc` argument order. See https://github.com/TokTok/hs-tokstyle/pull/102 --- toxav/audio.c | 6 +++--- toxav/bwcontroller.c | 2 +- toxav/groupav.c | 4 ++-- toxav/msi.c | 6 +++--- toxav/ring_buffer.c | 2 +- toxav/toxav.c | 6 +++--- toxav/video.c | 2 +- toxcore/TCP_client.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/toxav/audio.c b/toxav/audio.c index 7ca97abec..5c8bef51d 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -28,7 +28,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8 ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) { - ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1); + ACSession *ac = (ACSession *)calloc(1, sizeof(ACSession)); if (!ac) { LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); @@ -273,13 +273,13 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity) size *= 2; } - struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1); + struct JitterBuffer *q = (struct JitterBuffer *)calloc(1, sizeof(struct JitterBuffer)); if (!q) { return nullptr; } - q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size); + q->queue = (struct RTPMessage **)calloc(size, sizeof(struct RTPMessage *)); if (!q->queue) { free(q); diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 2d40ffe3c..da1e8ee7f 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -62,7 +62,7 @@ static void send_update(BWController *bwc); BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data, Mono_Time *bwc_mono_time) { - BWController *retu = (BWController *)calloc(sizeof(BWController), 1); + BWController *retu = (BWController *)calloc(1, sizeof(BWController)); if (retu == nullptr) { return nullptr; diff --git a/toxav/groupav.c b/toxav/groupav.c index da25c20b0..af70d95c7 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c @@ -37,13 +37,13 @@ static Group_JitterBuffer *create_queue(unsigned int capacity) size *= 2; } - Group_JitterBuffer *q = (Group_JitterBuffer *)calloc(sizeof(Group_JitterBuffer), 1); + Group_JitterBuffer *q = (Group_JitterBuffer *)calloc(1, sizeof(Group_JitterBuffer)); if (!q) { return nullptr; } - q->queue = (Group_Audio_Packet **)calloc(sizeof(Group_Audio_Packet *), size); + q->queue = (Group_Audio_Packet **)calloc(size, sizeof(Group_Audio_Packet *)); if (!q->queue) { free(q); diff --git a/toxav/msi.c b/toxav/msi.c index a03d28e74..b6d63f5da 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -94,7 +94,7 @@ MSISession *msi_new(Messenger *m) return nullptr; } - MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1); + MSISession *retu = (MSISession *)calloc(1, sizeof(MSISession)); if (retu == nullptr) { LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); @@ -530,7 +530,7 @@ static MSICall *new_call(MSISession *session, uint32_t friend_number) { assert(session); - MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1); + MSICall *rc = (MSICall *)calloc(1, sizeof(MSICall)); if (rc == nullptr) { return nullptr; @@ -540,7 +540,7 @@ static MSICall *new_call(MSISession *session, uint32_t friend_number) rc->friend_number = friend_number; if (session->calls == nullptr) { /* Creating */ - session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1); + session->calls = (MSICall **)calloc(friend_number + 1, sizeof(MSICall *)); if (session->calls == nullptr) { free(rc); diff --git a/toxav/ring_buffer.c b/toxav/ring_buffer.c index 432ee8e5a..783c4c90d 100644 --- a/toxav/ring_buffer.c +++ b/toxav/ring_buffer.c @@ -66,7 +66,7 @@ bool rb_read(RingBuffer *b, void **p) RingBuffer *rb_new(int size) { - RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1); + RingBuffer *buf = (RingBuffer *)calloc(1, sizeof(RingBuffer)); if (!buf) { return nullptr; diff --git a/toxav/toxav.c b/toxav/toxav.c index 020c1b6a1..d4fe2a1a4 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -165,7 +165,7 @@ ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error) goto RETURN; } - av = (ToxAV *)calloc(sizeof(ToxAV), 1); + av = (ToxAV *)calloc(1, sizeof(ToxAV)); if (av == nullptr) { LOGGER_WARNING(m->log, "Allocation failed!"); @@ -1244,7 +1244,7 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er goto RETURN; } - call = (ToxAVCall *)calloc(sizeof(ToxAVCall), 1); + call = (ToxAVCall *)calloc(1, sizeof(ToxAVCall)); if (call == nullptr) { rc = TOXAV_ERR_CALL_MALLOC; @@ -1262,7 +1262,7 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er } if (av->calls == nullptr) { /* Creating */ - av->calls = (ToxAVCall **)calloc(sizeof(ToxAVCall *), friend_number + 1); + av->calls = (ToxAVCall **)calloc(friend_number + 1, sizeof(ToxAVCall *)); if (av->calls == nullptr) { pthread_mutex_destroy(call->toxav_call_mutex); diff --git a/toxav/video.c b/toxav/video.c index f7e95f1c5..e62fc3bf8 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -143,7 +143,7 @@ static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) { - VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1); + VCSession *vc = (VCSession *)calloc(1, sizeof(VCSession)); vpx_codec_err_t rc; if (!vc) { diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 9899a9395..b3bf291bc 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -698,7 +698,7 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip return nullptr; } - TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(sizeof(TCP_Client_Connection), 1); + TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(1, sizeof(TCP_Client_Connection)); if (temp == nullptr) { kill_sock(sock);