diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 6f3f4d00..f1adcc7e 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -67,6 +67,11 @@ BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb, Mono_Time *bwc_mono_time) { BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1); + + if (retu == nullptr) { + return nullptr; + } + LOGGER_DEBUG(m->log, "Creating bandwidth controller"); retu->mcb = mcb; retu->mcb_user_data = mcb_user_data; diff --git a/toxav/ring_buffer.c b/toxav/ring_buffer.c index d4041fe9..e8019f6f 100644 --- a/toxav/ring_buffer.c +++ b/toxav/ring_buffer.c @@ -32,6 +32,10 @@ bool rb_empty(const RingBuffer *b) */ void *rb_write(RingBuffer *b, void *p) { + if (b == nullptr) { + return p; + } + void *rc = nullptr; if ((b->end + 1) % b->size == b->start) { /* full */ diff --git a/toxav/rtp.c b/toxav/rtp.c index 69aed2dc..36c91565 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -578,7 +578,13 @@ NEW_MULTIPARTED: /* Store message. */ session->mp = new_message(&header, header.data_length_lower, data + RTP_HEADER_SIZE, length - RTP_HEADER_SIZE); - memmove(session->mp->data + header.offset_lower, session->mp->data, session->mp->len); + + if (session->mp != nullptr) { + memmove(session->mp->data + header.offset_lower, session->mp->data, session->mp->len); + } else { + LOGGER_WARNING(m->log, "new_message() returned a null pointer"); + return -1; + } } return 0; diff --git a/toxav/toxav.c b/toxav/toxav.c index 3a46f0bb..298bb813 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -1302,7 +1302,7 @@ static bool call_prepare_transmission(ToxAVCall *call) ToxAV *av = call->av; - if (!av->acb && !av->vcb) { + if (av->acb == nullptr && av->vcb == nullptr) { /* It makes no sense to have CSession without callbacks */ return false; } @@ -1323,10 +1323,15 @@ static bool call_prepare_transmission(ToxAVCall *call) /* Prepare bwc */ call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time); + if (call->bwc == nullptr) { + LOGGER_ERROR(av->m->log, "Failed to create new bwc"); + goto FAILURE; + } + { /* Prepare audio */ call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data); - if (!call->audio) { + if (call->audio == nullptr) { LOGGER_ERROR(av->m->log, "Failed to create audio codec session"); goto FAILURE; } @@ -1334,15 +1339,16 @@ static bool call_prepare_transmission(ToxAVCall *call) call->audio_rtp = rtp_new(RTP_TYPE_AUDIO, av->m, av->tox, call->friend_number, call->bwc, call->audio, ac_queue_message); - if (!call->audio_rtp) { + if (call->audio_rtp == nullptr) { LOGGER_ERROR(av->m->log, "Failed to create audio rtp session"); goto FAILURE; } } + { /* Prepare video */ call->video = vc_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data); - if (!call->video) { + if (call->video == nullptr) { LOGGER_ERROR(av->m->log, "Failed to create video codec session"); goto FAILURE; } @@ -1350,7 +1356,7 @@ static bool call_prepare_transmission(ToxAVCall *call) call->video_rtp = rtp_new(RTP_TYPE_VIDEO, av->m, av->tox, call->friend_number, call->bwc, call->video, vc_queue_message); - if (!call->video_rtp) { + if (call->video_rtp == nullptr) { LOGGER_ERROR(av->m->log, "Failed to create video rtp session"); goto FAILURE; } diff --git a/toxcore/group.c b/toxcore/group.c index d1a9b659..4b331f98 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1542,6 +1542,10 @@ static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t fri { Group_c *g = get_group_c(g_c, groupnumber); + if (g == nullptr) { + return false; + } + const bool member = (g->status == GROUPCHAT_STATUS_CONNECTED); VLA(uint8_t, response, member ? INVITE_MEMBER_PACKET_SIZE : INVITE_ACCEPT_PACKET_SIZE);