Remove return after no-return situation (and other cleanups).

Cleanups:
- Fix header guards to not use reserved names.
- Avoid name shadowing.
- Removed an unused variable found by avoiding name shadowing.
This commit is contained in:
iphydf 2016-09-30 15:15:50 +01:00
parent 949ef785a4
commit 1977d56caa
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
21 changed files with 57 additions and 79 deletions

View File

@ -37,7 +37,7 @@ static const unsigned char bobpk[32] = {
0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
};
static const unsigned char nonce[24] = {
static const unsigned char test_nonce[24] = {
0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
@ -96,12 +96,12 @@ START_TEST(test_known)
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
clen = encrypt_data(bobpk, alicesk, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
mlen = decrypt_data(bobpk, alicesk, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
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");
@ -122,12 +122,12 @@ START_TEST(test_fast_known)
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
clen = encrypt_data_symmetric(k, nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(unsigned char), c);
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
ck_assert_msg(clen == sizeof(c) / sizeof(unsigned char), "wrong ciphertext length");
mlen = decrypt_data_symmetric(k, nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(unsigned char), m);
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");

View File

@ -434,9 +434,6 @@ static void test_list_main(void)
uint8_t cmp_list1[NUM_DHT][MAX_FRIEND_CLIENTS][crypto_box_PUBLICKEYBYTES + 1];
memset(cmp_list1, 0, sizeof(cmp_list1));
IP ip;
ip_init(&ip, 1);
unsigned int i, j, k, l;
for (i = 0; i < NUM_DHT; ++i) {

View File

@ -19,7 +19,7 @@
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
#endif
static unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F};
static unsigned char test_salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F};
static unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8};
static const char *pw = "hunter2";
static unsigned int pwlen = 7;
@ -46,7 +46,7 @@ START_TEST(test_known_kdf)
crypto_box_BEFORENMBYTES,
pw,
pwlen,
salt,
test_salt,
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE * 8,
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
ck_assert_msg(res != -1, "crypto function failed");
@ -103,7 +103,7 @@ START_TEST(test_save_friend)
uint8_t data2[size];
tox_get_savedata(tox3, data2);
TOX_PASS_KEY key;
memcpy(key.salt, salt, 32);
memcpy(key.salt, test_salt, 32);
memcpy(key.key, known_key2, crypto_box_BEFORENMBYTES);
size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t encdata2[size2];

View File

@ -155,12 +155,10 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
if (kind != TOX_FILE_KIND_DATA) {
ck_abort_msg("Bad kind");
return;
}
if (!(filename_length == sizeof("Gentoo.exe") && memcmp(filename, "Gentoo.exe", sizeof("Gentoo.exe")) == 0)) {
ck_abort_msg("Bad filename");
return;
}
uint8_t file_id[TOX_FILE_ID_LENGTH];
@ -244,7 +242,6 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
if (sending_pos != position) {
ck_abort_msg("Bad position %llu", position);
return;
}
if (length == 0) {
@ -293,7 +290,6 @@ static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uin
if (size_recv != position) {
ck_abort_msg("Bad position");
return;
}
if (length == 0) {
@ -897,13 +893,13 @@ loop_top:
tox_self_get_address(toxes[pairs[i].tox1], address);
TOX_ERR_FRIEND_ADD test;
uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
uint32_t friend_num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) {
goto loop_top;
}
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
ck_assert_msg(friend_num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
}
for (i = 0; i < NUM_TOXES; ++i) {
@ -1010,13 +1006,13 @@ loop_top:
tox_self_get_address(toxes[pairs[i].tox1], address);
TOX_ERR_FRIEND_ADD test;
uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
uint32_t friend_num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) {
goto loop_top;
}
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
ck_assert_msg(friend_num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
}
while (1) {
@ -1109,13 +1105,13 @@ loop_top:
tox_self_get_address(toxes[pairs[i].tox1], address);
TOX_ERR_FRIEND_ADD test;
uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
uint32_t friend_num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test);
if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) {
goto loop_top;
}
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
ck_assert_msg(friend_num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test);
}
uint16_t last_count = 0;

View File

@ -226,11 +226,11 @@ START_TEST(test_AV_flows)
memset(&AliceCC, 0, sizeof(CallControl)); \
memset(&BobCC, 0, sizeof(CallControl)); \
\
TOXAV_ERR_CALL rc; \
toxav_call(AliceAV, 0, A_BR, V_BR, &rc); \
TOXAV_ERR_CALL call_err; \
toxav_call(AliceAV, 0, A_BR, V_BR, &call_err); \
\
if (rc != TOXAV_ERR_CALL_OK) { \
printf("toxav_call failed: %d\n", rc); \
if (call_err != TOXAV_ERR_CALL_OK) { \
printf("toxav_call failed: %d\n", call_err); \
ck_assert(0); \
} \
\
@ -241,11 +241,11 @@ START_TEST(test_AV_flows)
while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { \
\
if (BobCC.incoming) { \
TOXAV_ERR_ANSWER rc; \
toxav_answer(BobAV, 0, A_BR, V_BR, &rc); \
TOXAV_ERR_ANSWER answer_err; \
toxav_answer(BobAV, 0, A_BR, V_BR, &answer_err); \
\
if (rc != TOXAV_ERR_ANSWER_OK) { \
printf("toxav_answer failed: %d\n", rc); \
if (answer_err != TOXAV_ERR_ANSWER_OK) { \
printf("toxav_answer failed: %d\n", answer_err); \
ck_assert(0); \
} \
BobCC.incoming = false; \
@ -254,11 +254,11 @@ START_TEST(test_AV_flows)
\
if (time(NULL) - start_time >= 1) { \
\
TOXAV_ERR_CALL_CONTROL rc; \
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); \
TOXAV_ERR_CALL_CONTROL cc_err; \
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); \
\
if (rc != TOXAV_ERR_CALL_CONTROL_OK) { \
printf("toxav_call_control failed: %d\n", rc); \
if (cc_err != TOXAV_ERR_CALL_CONTROL_OK) { \
printf("toxav_call_control failed: %d\n", cc_err); \
ck_assert(0); \
} \
} \

View File

@ -203,6 +203,4 @@ int main(int argc, char *argv[])
c_sleep(1);
}
return 0;
}

View File

@ -339,6 +339,4 @@ int main(int argc, char *argv[])
SLEEP_MILLISECONDS(30);
}
return 1;
}

View File

@ -259,6 +259,4 @@ int main(int argc, char *argv[])
print_friendlist(dht);
c_sleep(300);
}
return 0;
}

View File

@ -67,7 +67,7 @@ static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type
* networking_requesthandler and so cannot take a Messenger * */
static Messenger *m;
static void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
static void print_request(Messenger *m2, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
{
printf("Friend request received from: \n");
printf("ClientID: ");
@ -91,7 +91,7 @@ static void print_request(Messenger *m, const uint8_t *public_key, const uint8_t
//if the request contained the message of peace the person is obviously a friend so we add him.
{
printf("Friend request accepted.\n");
m_addfriend_norequest(m, public_key);
m_addfriend_norequest(m2, public_key);
}
}

View File

@ -47,9 +47,9 @@ static uint64_t get_monotime_sec(void)
static int reconnect(void)
{
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
int new_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
if (new_sock < 0) {
printf("error socket\n");
return -1;
}
@ -68,14 +68,14 @@ static int reconnect(void)
addr4->sin_port = htons(port);
if (connect(sock, (struct sockaddr *)&addr, addrsize) != 0) {
if (connect(new_sock, (struct sockaddr *)&addr, addrsize) != 0) {
printf("error connect\n");
return -1;
}
send(sock, SERVER_CONNECT, sizeof(SERVER_CONNECT) - 1, MSG_NOSIGNAL);
send(new_sock, SERVER_CONNECT, sizeof(SERVER_CONNECT) - 1, MSG_NOSIGNAL);
return sock;
return new_sock;
}
#include "../toxcore/tox.h"
@ -256,9 +256,9 @@ static Tox *init_tox(int argc, char *argv[])
exit(1);
}
uint16_t port = atoi(argv[argvoffset + 2]);
uint16_t bootstrap_port = atoi(argv[argvoffset + 2]);
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
tox_bootstrap(tox, argv[argvoffset + 1], port, binary_string, 0);
tox_bootstrap(tox, argv[argvoffset + 1], bootstrap_port, binary_string, 0);
free(binary_string);
uint8_t *bin_id = hex_string_to_bin(temp_id);
@ -372,6 +372,4 @@ int main(int argc, char *argv[])
tox_iterate(tox, NULL);
usleep(1000 * 50);
}
return 0;
}

View File

@ -1233,7 +1233,6 @@ static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_n
if (file_senders[i].file && file_senders[i].friendnum == friend_number && file_senders[i].filenumber == file_number) {
fclose(file_senders[i].file);
file_senders[i].file = 0;
char msg[512];
sprintf(msg, "[t] %u file transfer: %u cancelled", file_senders[i].friendnum, file_senders[i].filenumber);
new_lines(msg);
}

View File

@ -159,6 +159,4 @@ int main(int argc, char *argv[])
tox_iterate(tox, master);
c_sleep(1);
}
return 0;
}

View File

@ -333,6 +333,4 @@ int main(int argc, char *argv[])
tox_iterate(tox, NULL);
c_sleep(1);
}
return 0;
}

View File

@ -668,13 +668,13 @@ void handle_init(MSICall *call, const MSIMessage *msg)
LOGGER_INFO(call->session->messenger->log, "Friend is recalling us");
MSIMessage msg;
msg_init(&msg, requ_push);
MSIMessage out_msg;
msg_init(&out_msg, requ_push);
msg.capabilities.exists = true;
msg.capabilities.value = call->self_capabilities;
out_msg.capabilities.exists = true;
out_msg.capabilities.value = call->self_capabilities;
send_message(call->session->messenger, call->friend_number, &msg);
send_message(call->session->messenger, call->friend_number, &out_msg);
/* If peer changed capabilities during re-call they will
* be handled accordingly during the next step

View File

@ -1686,10 +1686,10 @@ static void do_Close(DHT *dht)
* so: reset all nodes to be BAD_NODE_TIMEOUT, but not
* KILL_NODE_TIMEOUT, so we at least keep trying pings */
uint64_t badonly = unix_time() - BAD_NODE_TIMEOUT;
size_t i, a;
size_t j, a;
for (i = 0; i < LCLIENT_LIST; i++) {
Client_data *client = &dht->close_clientlist[i];
for (j = 0; j < LCLIENT_LIST; j++) {
Client_data *client = &dht->close_clientlist[j];
IPPTsPng *assoc;
for (a = 0, assoc = &client->assoc4; a < 2; a++, assoc = &client->assoc6) {

View File

@ -1,5 +1,5 @@
#ifndef __ASSOC_H__
#define __ASSOC_H__
#ifndef ASSOC_H
#define ASSOC_H
#include "DHT.h"
#include "logger.h"
@ -105,4 +105,4 @@ void kill_Assoc(Assoc *assoc);
void Assoc_status(Logger *log, const Assoc *assoc);
#endif /* !__ASSOC_H__ */
#endif /* !ASSOC_H */

View File

@ -1552,8 +1552,6 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
return -1;
}
}
return 0;
}
/* Set the size of the friend list to numfriends.
@ -2321,7 +2319,7 @@ static void send_crypto_packets(Net_Crypto *c)
if (conn->status == CRYPTO_CONN_ESTABLISHED) {
if (conn->packet_recv_rate > CRYPTO_PACKET_MIN_RATE) {
double request_packet_interval = (REQUEST_PACKETS_COMPARE_CONSTANT / (((double)num_packets_array(
double request_packet_interval = (REQUEST_PACKETS_COMPARE_CONSTANT / ((num_packets_array(
&conn->recv_array) + 1.0) / (conn->packet_recv_rate + 1.0)));
double request_packet_interval2 = ((CRYPTO_PACKET_MIN_RATE / conn->packet_recv_rate) *

View File

@ -21,7 +21,7 @@
*
*/
#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP)
#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP
#define _WIN32_WINNT 0x501
#endif

View File

@ -21,8 +21,8 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PING_H__
#define __PING_H__
#ifndef PING_H
#define PING_H
#include "DHT.h"
#include "network.h"
@ -49,4 +49,4 @@ void kill_ping(PING *ping);
int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *public_key);
#endif /* __PING_H__ */
#endif /* PING_H */

View File

@ -22,8 +22,8 @@
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#ifndef UTIL_H
#define UTIL_H
#include <pthread.h>
#include <stdbool.h>
@ -58,4 +58,4 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
/* Returns -1 if failed or 0 if success */
int create_recursive_mutex(pthread_mutex_t *mutex);
#endif /* __UTIL_H__ */
#endif /* UTIL_H */

View File

@ -37,14 +37,14 @@ static const char base32[32] = {
#define _encode(a, b, c) \
{ \
uint8_t i = 0; \
while(i != c) { \
uint8_t _i = 0; \
while (_i != c) { \
*a++ = base32[((b[0] >> bits) | (b[1] << (8 - bits))) & 0x1F]; \
bits += 5; \
if(bits >= 8) { \
bits -= 8; \
b++; \
i++; \
_i++; \
} \
} \
}