From a9fbdaf46b23db5c598bf33d6bc5c4555b06e674 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 31 Aug 2016 20:40:20 +0100 Subject: Do not use `else` after `return`. http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code --- toxav/audio.c | 12 ++--- toxav/group.c | 1 - toxav/msi.c | 9 +--- toxav/rtp.c | 164 +++++++++++++++++++++++++++++----------------------------- toxav/toxav.c | 2 - 5 files changed, 90 insertions(+), 98 deletions(-) (limited to 'toxav') diff --git a/toxav/audio.c b/toxav/audio.c index eaa1f6d0..c0bfa608 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -413,13 +413,13 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int *e = new_encoder; } else if (*old_br == new_br) { return true; /* Nothing changed */ - } else { - int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br)); + } - if (status != OPUS_OK) { - LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status)); - return false; - } + int status = opus_encoder_ctl(*e, OPUS_SET_BITRATE(new_br)); + + if (status != OPUS_OK) { + LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status)); + return false; } *old_br = new_br; diff --git a/toxav/group.c b/toxav/group.c index dea10af7..969250f8 100644 --- a/toxav/group.c +++ b/toxav/group.c @@ -370,7 +370,6 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g if (out_audio_samples <= 0) { return -1; } - } if (out_audio) { diff --git a/toxav/msi.c b/toxav/msi.c index 3becac7e..a62bdb35 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -46,7 +46,6 @@ typedef enum { IDRequest = 1, IDError, IDCapabilities, - } MSIHeaderID; @@ -538,7 +537,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number) } session->calls_tail = session->calls_head = friend_number; - } else if (session->calls_tail < friend_number) { /* Appending */ void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); @@ -560,7 +558,6 @@ MSICall *new_call (MSISession *session, uint32_t friend_number) session->calls[session->calls_tail]->next = rc; session->calls_tail = friend_number; - } else if (session->calls_head > friend_number) { /* Inserting at front */ rc->next = session->calls[session->calls_head]; session->calls[session->calls_head]->prev = rc; @@ -736,7 +733,6 @@ void handle_push (MSICall *call, const MSIMessage *msg) if (invoke_callback(call, msi_OnStart) == -1) { goto FAILURE; } - } break; @@ -767,7 +763,6 @@ void handle_pop (MSICall *call, const MSIMessage *msg) LOGGER_WARNING(call->session->messenger->log, "Friend detected an error: %d", msg->error.value); call->error = msg->error.value; invoke_callback(call, msi_OnError); - } else { switch (call->state) { case msi_CallInactive: { @@ -812,10 +807,10 @@ void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *dat LOGGER_WARNING(m->log, "Error parsing message"); send_error(m, friend_number, msi_EInvalidMessage); return; - } else { - LOGGER_DEBUG(m->log, "Successfully parsed message"); } + LOGGER_DEBUG(m->log, "Successfully parsed message"); + pthread_mutex_lock(session->mutex); MSICall *call = get_call(session, friend_number); diff --git a/toxav/rtp.c b/toxav/rtp.c index 1556d23d..38e64dd7 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -268,12 +268,12 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, */ if (chloss(session, header)) { return 0; - } else { - /* Message is not late; pick up the latest parameters */ - session->rsequnum = ntohs(header->sequnum); - session->rtimestamp = ntohl(header->timestamp); } + /* Message is not late; pick up the latest parameters */ + session->rsequnum = ntohs(header->sequnum); + session->rtimestamp = ntohl(header->timestamp); + bwc_add_recv(session->bwc, length); /* Invoke processing of active multiparted message */ @@ -296,69 +296,43 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, } return session->mcb (session->cs, new_message(length, data, length)); - } else { - /* The message is sent in multiple parts */ - - if (session->mp) { - /* 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. - * - * We handle them differently as we only allow a single multiparted - * processing message - */ - - if (session->mp->header.sequnum == ntohs(header->sequnum) && - session->mp->header.timestamp == ntohl(header->timestamp)) { - /* First case */ - - /* Make sure we have enough allocated memory */ - if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || - session->mp->header.tlen <= ntohs(header->cpart)) { - /* There happened to be some corruption on the stream; - * continue wihtout this part - */ - return 0; - } - - memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader), - length - sizeof(struct RTPHeader)); + } - session->mp->len += length - sizeof(struct RTPHeader); + /* The message is sent in multiple parts */ - bwc_add_recv(session->bwc, length); + if (session->mp) { + /* 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. + * + * We handle them differently as we only allow a single multiparted + * processing message + */ - if (session->mp->len == session->mp->header.tlen) { - /* Received a full message; now push it for the further - * processing. - */ - if (session->mcb) { - session->mcb (session->cs, session->mp); - } else { - free(session->mp); - } + if (session->mp->header.sequnum == ntohs(header->sequnum) && + session->mp->header.timestamp == ntohl(header->timestamp)) { + /* First case */ - session->mp = NULL; - } - } else { - /* Second case */ + /* Make sure we have enough allocated memory */ + if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || + session->mp->header.tlen <= ntohs(header->cpart)) { + /* There happened to be some corruption on the stream; + * continue wihtout this part + */ + return 0; + } - if (session->mp->header.timestamp > ntohl(header->timestamp)) { - /* The received message part is from the old message; - * discard it. - */ - return 0; - } + memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader), + length - sizeof(struct RTPHeader)); - /* Measure missing parts of the old message */ - bwc_add_lost(session->bwc, - (session->mp->header.tlen - session->mp->len) + + session->mp->len += length - sizeof(struct RTPHeader); - /* Must account sizes of rtp headers too */ - ((session->mp->header.tlen - session->mp->len) / - MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) ); + bwc_add_recv(session->bwc, length); - /* Push the previous message for processing */ + if (session->mp->len == session->mp->header.tlen) { + /* Received a full message; now push it for the further + * processing. + */ if (session->mcb) { session->mcb (session->cs, session->mp); } else { @@ -366,40 +340,66 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, } session->mp = NULL; - goto NEW_MULTIPARTED; } } else { - /* In this case threat the message as if it was received in order - */ - - /* This is also a point for new multiparted messages */ -NEW_MULTIPARTED: + /* Second case */ - /* Only allow messages which have arrived in order; - * drop late messages - */ - if (chloss(session, header)) { + if (session->mp->header.timestamp > ntohl(header->timestamp)) { + /* The received message part is from the old message; + * discard it. + */ return 0; - } else { - /* Message is not late; pick up the latest parameters */ - session->rsequnum = ntohs(header->sequnum); - session->rtimestamp = ntohl(header->timestamp); } - bwc_add_recv(session->bwc, length); + /* Measure missing parts of the old message */ + bwc_add_lost(session->bwc, + (session->mp->header.tlen - session->mp->len) + + + /* Must account sizes of rtp headers too */ + ((session->mp->header.tlen - session->mp->len) / + MAX_CRYPTO_DATA_SIZE) * sizeof(struct RTPHeader) ); - /* Again, only store message if handler is present - */ + /* Push the previous message for processing */ if (session->mcb) { - session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); + session->mcb (session->cs, session->mp); + } else { + free(session->mp); + } - /* Reposition data if necessary */ - if (ntohs(header->cpart)) { - ; - } + session->mp = NULL; + goto NEW_MULTIPARTED; + } + } else { + /* In this case threat the message as if it was received in order + */ + + /* This is also a point for new multiparted messages */ +NEW_MULTIPARTED: + + /* Only allow messages which have arrived in order; + * drop late messages + */ + if (chloss(session, header)) { + return 0; + } + + /* Message is not late; pick up the latest parameters */ + session->rsequnum = ntohs(header->sequnum); + session->rtimestamp = ntohl(header->timestamp); - memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); + bwc_add_recv(session->bwc, length); + + /* Again, only store message if handler is present + */ + if (session->mcb) { + session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); + + /* Reposition data if necessary */ + if (ntohs(header->cpart)) { + ; } + + memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); } } diff --git a/toxav/toxav.c b/toxav/toxav.c index 126e29a7..749519a2 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -1087,7 +1087,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error) } av->calls_tail = av->calls_head = friend_number; - } else if (av->calls_tail < friend_number) { /* Appending */ void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); @@ -1111,7 +1110,6 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error) av->calls[av->calls_tail]->next = call; av->calls_tail = friend_number; - } else if (av->calls_head > friend_number) { /* Inserting at front */ call->next = av->calls[av->calls_head]; av->calls[av->calls_head]->prev = call; -- cgit v1.2.3