mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Add some missing null checks
This commit is contained in:
parent
d930ecca4c
commit
ce268c2f82
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user