Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Avoid implicit pointer-to-bool conversion in if in toxav. #2046

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ jobs:
(find . -name "*.py" -and -not -name "conanfile.py"; grep -lR '^#!.*python') \
| xargs -n1 -P8 mypy --strict

tokstyle:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Build
uses: docker/build-push-action@v2
with:
file: other/docker/tokstyle/Dockerfile

build-msan:
runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
gcc \
git \
libmsgpack-dev \
libopus-dev \
libsodium-dev \
libvpx-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY --from=tokstyle /bin/check-c /bin/
RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/hs-tokstyle", "/src/workspace/hs-tokstyle"]

COPY toxav/ /src/workspace/c-toxcore/toxcore/
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
RUN /bin/check-c /src/workspace/c-toxcore/toxcore/*.c
RUN /bin/check-c $(find /src/workspace/c-toxcore -name "*.c")
3 changes: 3 additions & 0 deletions other/docker/tokstyle/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker build -f other/docker/tokstyle/Dockerfile .
3 changes: 0 additions & 3 deletions other/docker/typecheck/run

This file was deleted.

6 changes: 3 additions & 3 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void ac_iterate(ACSession *ac)

if (rc < 0) {
LOGGER_WARNING(ac->log, "Decoding error: %s", opus_strerror(rc));
} else if (ac->acb) {
} else if (ac->acb != nullptr) {
ac->lp_frame_duration = (rc * 1000) / ac->lp_sampling_rate;

ac->acb(ac->av, ac->friend_number, temp_audio_buffer, rc, ac->lp_channel_count,
Expand Down Expand Up @@ -324,7 +324,7 @@ static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessa
return 0;
}

if (q->queue[num]) {
if (q->queue[num] != nullptr) {
return -1;
}

Expand All @@ -345,7 +345,7 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)

unsigned int num = q->bottom % q->size;

if (q->queue[num]) {
if (q->queue[num] != nullptr) {
struct RTPMessage *ret = q->queue[num];
q->queue[num] = nullptr;
++q->bottom;
Expand Down
18 changes: 9 additions & 9 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int queue(Group_JitterBuffer *q, const Mono_Time *mono_time, Group_Audio_
return 0;
}

if (q->queue[num]) {
if (q->queue[num] != nullptr) {
return -1;
}

Expand All @@ -134,7 +134,7 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)

unsigned int num = q->bottom % q->size;

if (q->queue[num]) {
if (q->queue[num] != nullptr) {
Group_Audio_Packet *ret = q->queue[num];
q->queue[num] = nullptr;
++q->bottom;
Expand Down Expand Up @@ -179,7 +179,7 @@ typedef struct Group_Peer_AV {

static void kill_group_av(Group_AV *group_av)
{
if (group_av->audio_encoder) {
if (group_av->audio_encoder != nullptr) {
opus_encoder_destroy(group_av->audio_encoder);
}

Expand All @@ -188,7 +188,7 @@ static void kill_group_av(Group_AV *group_av)

static int recreate_encoder(Group_AV *group_av)
{
if (group_av->audio_encoder) {
if (group_av->audio_encoder != nullptr) {
opus_encoder_destroy(group_av->audio_encoder);
group_av->audio_encoder = nullptr;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ static void group_av_peer_delete(void *object, uint32_t groupnumber, void *peer_
return;
}

if (peer_av->audio_decoder) {
if (peer_av->audio_decoder != nullptr) {
opus_decoder_destroy(peer_av->audio_decoder);
}

Expand All @@ -282,7 +282,7 @@ static void group_av_peer_delete(void *object, uint32_t groupnumber, void *peer_

static void group_av_groupchat_delete(void *object, uint32_t groupnumber)
{
if (object) {
if (object != nullptr) {
kill_group_av((Group_AV *)object);
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
}

if (channels != peer_av->decoder_channels) {
if (peer_av->audio_decoder) {
if (peer_av->audio_decoder != nullptr) {
opus_decoder_destroy(peer_av->audio_decoder);
peer_av->audio_decoder = nullptr;
}
Expand Down Expand Up @@ -379,9 +379,9 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
}
}

if (out_audio) {
if (out_audio != nullptr) {

if (group_av->audio_data) {
if (group_av->audio_data != nullptr) {
group_av->audio_data(group_av->tox, groupnumber, friendgroupnumber, out_audio, out_audio_samples,
peer_av->decoder_channels, sample_rate, group_av->userdata);
}
Expand Down
10 changes: 5 additions & 5 deletions toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int msi_kill(MSISession *session, const Logger *log)
return -1;
}

if (session->calls) {
if (session->calls != nullptr) {
MSIMessage msg;
msg_init(&msg, REQU_POP);

Expand Down Expand Up @@ -625,17 +625,17 @@ static void kill_call(MSICall *call)
MSICall *prev = call->prev;
MSICall *next = call->next;

if (prev) {
if (prev != nullptr) {
prev->next = next;
} else if (next) {
} else if (next != nullptr) {
session->calls_head = next->friend_number;
} else {
goto CLEAR_CONTAINER;
}

if (next) {
if (next != nullptr) {
next->prev = prev;
} else if (prev) {
} else if (prev != nullptr) {
session->calls_tail = prev->friend_number;
} else {
goto CLEAR_CONTAINER;
Expand Down
2 changes: 1 addition & 1 deletion toxav/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ RingBuffer *rb_new(int size)

void rb_kill(RingBuffer *b)
{
if (b) {
if (b != nullptr) {
free(b->data);
free(b);
}
Expand Down
6 changes: 3 additions & 3 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static int handle_video_packet(RTPSession *session, const struct RTPHeader *head

struct RTPMessage *m_new = process_frame(log, session->work_buffer_list, slot_id);

if (m_new) {
if (m_new != nullptr) {
LOGGER_DEBUG(log, "-- handle_video_packet -- CALLBACK-003a b0=%d b1=%d", (int)m_new->data[0], (int)m_new->data[1]);
update_bwc_values(log, session, m_new);
session->mcb(session->m->mono_time, session->cs, m_new);
Expand Down Expand Up @@ -498,7 +498,7 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t
bwc_add_recv(session->bwc, length);

/* Invoke processing of active multiparted message */
if (session->mp) {
if (session->mp != nullptr) {
session->mcb(session->m->mono_time, session->cs, session->mp);
session->mp = nullptr;
}
Expand All @@ -512,7 +512,7 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t

/* The message is sent in multiple parts */

if (session->mp) {
if (session->mp != nullptr) {
/* There are 2 possible situations in this case:
* 1) being that we got the part of already processing message.
* 2) being that we got the part of a new/old message.
Expand Down
42 changes: 21 additions & 21 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error)
m = *(Messenger **)tox;
//!TOKSTYLE+

if (m->msi_packet) {
if (m->msi_packet != nullptr) {
rc = TOXAV_ERR_NEW_MULTIPLE;
goto RETURN;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error)

RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand All @@ -229,7 +229,7 @@ void toxav_kill(ToxAV *av)
}

/* Msi kill will hang up all calls so just clean these calls */
if (av->calls) {
if (av->calls != nullptr) {
ToxAVCall *it = call_get(av, av->calls_head);

while (it) {
Expand Down Expand Up @@ -400,7 +400,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
RETURN:
pthread_mutex_unlock(av->mutex);

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -460,7 +460,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
RETURN:
pthread_mutex_unlock(av->mutex);

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -632,7 +632,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co

pthread_mutex_unlock(av->mutex);

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -704,7 +704,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
pthread_mutex_unlock(av->mutex);
RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -776,7 +776,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
pthread_mutex_unlock(av->mutex);
RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -874,7 +874,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc

RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -1022,7 +1022,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u

RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ static int callback_invite(void *toxav_inst, MSICall *call)
call->av_call = av_call;
av_call->msi_call = call;

if (toxav->ccb) {
if (toxav->ccb != nullptr) {
toxav->ccb(toxav, call->friend_number, call->peer_capabilities & MSI_CAP_S_AUDIO,
call->peer_capabilities & MSI_CAP_S_VIDEO, toxav->ccb_user_data);
} else {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ static int callback_end(void *toxav_inst, MSICall *call)

invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_FINISHED);

if (call->av_call) {
if (call->av_call != nullptr) {
call_kill_transmission(call->av_call);
call_remove(call->av_call);
}
Expand All @@ -1173,7 +1173,7 @@ static int callback_error(void *toxav_inst, MSICall *call)

invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_ERROR);

if (call->av_call) {
if (call->av_call != nullptr) {
call_kill_transmission(call->av_call);
call_remove(call->av_call);
}
Expand Down Expand Up @@ -1219,11 +1219,11 @@ static bool video_bit_rate_invalid(uint32_t bit_rate)
* we may want to prevent from passing overflowed bitrates to libvpx
* more in detail, it's the case where bit_rate is larger than uint, but smaller than uint32_t
*/
return bit_rate > UINT_MAX;
return bit_rate > UINT32_MAX;
}
static bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state)
{
if (av->scb) {
if (av->scb != nullptr) {
av->scb(av, friend_number, state, av->scb_user_data);
} else {
return false;
Expand Down Expand Up @@ -1315,7 +1315,7 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er

RETURN:

if (error) {
if (error != nullptr) {
*error = rc;
}

Expand Down Expand Up @@ -1347,24 +1347,24 @@ static ToxAVCall *call_remove(ToxAVCall *call)
/* Set av call in msi to NULL in order to know if call if ToxAVCall is
* removed from the msi call.
*/
if (call->msi_call) {
if (call->msi_call != nullptr) {
call->msi_call->av_call = nullptr;
}

pthread_mutex_destroy(call->toxav_call_mutex);
free(call);

if (prev) {
if (prev != nullptr) {
prev->next = next;
} else if (next) {
} else if (next != nullptr) {
av->calls_head = next->friend_number;
} else {
goto CLEAR;
}

if (next) {
if (next != nullptr) {
next->prev = prev;
} else if (prev) {
} else if (prev != nullptr) {
av->calls_tail = prev->friend_number;
} else {
goto CLEAR;
Expand Down
4 changes: 2 additions & 2 deletions toxav/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void vc_iterate(VCSession *vc)
for (vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter);
dest != nullptr;
dest = vpx_codec_get_frame(vc->decoder, &iter)) {
if (vc->vcb) {
if (vc->vcb != nullptr) {
vc->vcb(vc->av, vc->friend_number, dest->d_w, dest->d_h,
(const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2],
dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb_user_data);
Expand All @@ -347,7 +347,7 @@ int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
* this function gets called from handle_rtp_packet() and handle_rtp_packet_v3()
*/
if (!vcp || !msg) {
if (msg) {
if (msg != nullptr) {
free(msg);
}

Expand Down