Skip to content

Commit

Permalink
Do not use else after return.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Sep 1, 2016
1 parent 579bdc1 commit 79d6cc1
Show file tree
Hide file tree
Showing 31 changed files with 410 additions and 409 deletions.
1 change: 0 additions & 1 deletion auto_tests/assoc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ START_TEST(test_fillup)
if (j % 16 == 0) {
memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30);
memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));

}

uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
Expand Down
1 change: 0 additions & 1 deletion auto_tests/crypto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ START_TEST(test_fast_known)

ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
ck_assert_msg(mlen == sizeof(m) / sizeof(unsigned char), "wrong plaintext length");

}
END_TEST

Expand Down
10 changes: 4 additions & 6 deletions auto_tests/dht_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigne
memcpy(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES);
cmp_list[i][crypto_box_PUBLICKEYBYTES] = 1;
return;
} else {
if (memcmp(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES) == 0) {
return;
}
}

if (memcmp(cmp_list[i], pk, crypto_box_PUBLICKEYBYTES) == 0) {
return;
}
}

Expand Down Expand Up @@ -557,8 +557,6 @@ END_TEST

void ip_callback(void *data, int32_t number, IP_Port ip_port)
{


}


Expand Down
45 changes: 21 additions & 24 deletions auto_tests/tox_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,12 @@ START_TEST(test_few_clients)
tox_iterate(tox2, &to_compare);
tox_iterate(tox3, &to_compare);


if (typing_changes == 2) {
break;
} else {
ck_assert_msg(typing_changes == 0, "Typing fail");
}

ck_assert_msg(typing_changes == 0, "Typing fail");

c_sleep(50);
}

Expand All @@ -635,10 +634,10 @@ START_TEST(test_few_clients)

if (typing_changes == 1) {
break;
} else {
ck_assert_msg(typing_changes == 0, "Typing fail");
}

ck_assert_msg(typing_changes == 0, "Typing fail");

c_sleep(50);
}

Expand All @@ -663,10 +662,10 @@ START_TEST(test_few_clients)

if (custom_packet == 1) {
break;
} else {
ck_assert_msg(custom_packet == 0, "Lossless packet fail");
}

ck_assert_msg(custom_packet == 0, "Lossless packet fail");

c_sleep(50);
}

Expand All @@ -686,10 +685,10 @@ START_TEST(test_few_clients)

if (custom_packet == 1) {
break;
} else {
ck_assert_msg(custom_packet == 0, "lossy packet fail");
}

ck_assert_msg(custom_packet == 0, "lossy packet fail");

c_sleep(50);
}

Expand Down Expand Up @@ -725,11 +724,11 @@ START_TEST(test_few_clients)
if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
&& file_accepted == 1) {
break;
} else {
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
sending_pos);
}

ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
sending_pos);
}

uint32_t tox1_interval = tox_iteration_interval(tox1);
Expand Down Expand Up @@ -772,12 +771,12 @@ START_TEST(test_few_clients)
if (sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
&& sending_pos == size_recv && file_accepted == 1) {
break;
} else {
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
totalf_size, file_size,
size_recv, sending_pos);
}

ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %u %llu %llu %llu %llu", sendf_ok, file_recv,
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
totalf_size, file_size,
size_recv, sending_pos);
}

uint32_t tox1_interval = tox_iteration_interval(tox1);
Expand Down Expand Up @@ -806,7 +805,6 @@ START_TEST(test_few_clients)
ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");


while (1) {
tox_iterate(tox1, &to_compare);
tox_iterate(tox2, &to_compare);
Expand All @@ -816,11 +814,11 @@ START_TEST(test_few_clients)
if (sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
&& file_accepted == 1) {
break;
} else {
ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
sending_pos);
}

ck_abort_msg("Something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size, size_recv,
sending_pos);
}

uint32_t tox1_interval = tox_iteration_interval(tox1);
Expand Down Expand Up @@ -1013,7 +1011,6 @@ START_TEST(test_many_clients_tcp)
++counter;
}
}

}

if (counter == NUM_FRIENDS * 2) {
Expand Down
1 change: 0 additions & 1 deletion auto_tests/toxav_basic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
typedef struct {
bool incoming;
uint32_t state;

} CallControl;


Expand Down
1 change: 0 additions & 1 deletion testing/DHT_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours)

printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
print_hardening(&assoc->hardening);

}

void print_clientlist(DHT *dht)
Expand Down
1 change: 0 additions & 1 deletion testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ int main(int argc, char *argv[])
read = fread(buffer, 1, 128000, file);
printf("Messenger loaded: %i\n", messenger_load(m, buffer, read));
fclose(file);

}

m_callback_friendrequest(m, print_request, NULL);
Expand Down
1 change: 0 additions & 1 deletion testing/av_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ typedef struct {
uint32_t state;
pthread_mutex_t arb_mutex[1];
RingBuffer *arb; /* Audio ring buffer */

} CallControl;

struct toxav_thread_data {
Expand Down
78 changes: 40 additions & 38 deletions testing/nTox.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ void line_eval(Tox *m, char *line)
new_lines_mark(help_friend1, 1);
new_lines_mark(help_friend2, 1);
return;
} else if (line[3] == 'g') {
}

if (line[3] == 'g') {
new_lines_mark(help_group, 1);
return;
}
Expand Down Expand Up @@ -779,56 +781,56 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si
}

continue;
} else {
/* at the limit */
if (bar_avail > nl_got) {
/* overwrite */
memcpy(output + bar_avail - 1, wrap_cont_str, wrap_cont_len);
nl_got = bar_avail;

ipos--;
continue;
}
}

if (space_avail > nl_got) {
if (opos + wrap_cont_len - 1 >= STRING_LENGTH_WRAPPED) {
opos = STRING_LENGTH_WRAPPED - 1;
break;
}
/* at the limit */
if (bar_avail > nl_got) {
/* overwrite */
memcpy(output + bar_avail - 1, wrap_cont_str, wrap_cont_len);
nl_got = bar_avail;

/* move forward by 2 characters */
memmove(output + space_avail + 3, output + space_avail + 1, opos - (space_avail + 1));
memcpy(output + space_avail, wrap_cont_str, wrap_cont_len);
nl_got = space_avail + 1;
ipos--;
continue;
}

opos += 2;
ipos--;
continue;
if (space_avail > nl_got) {
if (opos + wrap_cont_len - 1 >= STRING_LENGTH_WRAPPED) {
opos = STRING_LENGTH_WRAPPED - 1;
break;
}

char c = input[ipos];
/* move forward by 2 characters */
memmove(output + space_avail + 3, output + space_avail + 1, opos - (space_avail + 1));
memcpy(output + space_avail, wrap_cont_str, wrap_cont_len);
nl_got = space_avail + 1;

if ((c == '|') || (c == ' ') || (c == '\n')) {
if (opos + wrap_cont_len >= STRING_LENGTH_WRAPPED) {
opos = STRING_LENGTH_WRAPPED - 1;
break;
}

memcpy(output + opos, wrap_cont_str, wrap_cont_len);

nl_got = opos;
opos += wrap_cont_len;
}
opos += 2;
ipos--;
continue;
}

output[opos++] = input[ipos];
char c = input[ipos];

if (opos >= STRING_LENGTH_WRAPPED) {
if ((c == '|') || (c == ' ') || (c == '\n')) {
if (opos + wrap_cont_len >= STRING_LENGTH_WRAPPED) {
opos = STRING_LENGTH_WRAPPED - 1;
break;
}

continue;
memcpy(output + opos, wrap_cont_str, wrap_cont_len);

nl_got = opos;
opos += wrap_cont_len;
}

output[opos++] = input[ipos];

if (opos >= STRING_LENGTH_WRAPPED) {
opos = STRING_LENGTH_WRAPPED - 1;
break;
}

continue;
}

if (opos >= STRING_LENGTH_WRAPPED) {
Expand Down
2 changes: 0 additions & 2 deletions testing/tox_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number,
if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) {
printf("Accepted file transfer. (file: %s)\n", fullpath);
}

}

void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control,
Expand Down Expand Up @@ -323,7 +322,6 @@ int main(int argc, char *argv[])
}

closedir(d);

} else {
printf("\nFailed to open directory.\n");
return 1;
Expand Down
12 changes: 6 additions & 6 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion toxav/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 2 additions & 7 deletions toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ typedef enum {
IDRequest = 1,
IDError,
IDCapabilities,

} MSIHeaderID;


Expand Down Expand Up @@ -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));

Expand All @@ -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;
Expand Down Expand Up @@ -736,7 +733,6 @@ void handle_push (MSICall *call, const MSIMessage *msg)
if (invoke_callback(call, msi_OnStart) == -1) {
goto FAILURE;
}

}
break;

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 79d6cc1

Please sign in to comment.