summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c86
-rw-r--r--toxcore/TCP_connection.c36
-rw-r--r--toxcore/net_crypto.c14
3 files changed, 67 insertions, 69 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 945d6556..93ed6495 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -28,16 +28,14 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_
28 uint32_t length, uint8_t congestion_control); 28 uint32_t length, uint8_t congestion_control);
29static void m_register_default_plugins(Messenger *m); 29static void m_register_default_plugins(Messenger *m);
30 30
31// friend_not_valid determines if the friendnumber passed is valid in the Messenger object 31/**
32static uint8_t friend_not_valid(const Messenger *m, int32_t friendnumber) 32 * Determines if the friendnumber passed is valid in the Messenger object.
33 *
34 * @param friendnumber The index in the friend list.
35 */
36static bool friend_is_valid(const Messenger *m, int32_t friendnumber)
33{ 37{
34 if ((unsigned int)friendnumber < m->numfriends) { 38 return (unsigned int)friendnumber < m->numfriends && m->friendlist[friendnumber].status != 0;
35 if (m->friendlist[friendnumber].status != 0) {
36 return 0;
37 }
38 }
39
40 return 1;
41} 39}
42 40
43/* Set the size of the friend list to numfriends. 41/* Set the size of the friend list to numfriends.
@@ -88,7 +86,7 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk)
88 */ 86 */
89int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk) 87int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk)
90{ 88{
91 if (friend_not_valid(m, friendnumber)) { 89 if (!friend_is_valid(m, friendnumber)) {
92 return -1; 90 return -1;
93 } 91 }
94 92
@@ -101,7 +99,7 @@ int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk)
101 */ 99 */
102int getfriendcon_id(const Messenger *m, int32_t friendnumber) 100int getfriendcon_id(const Messenger *m, int32_t friendnumber)
103{ 101{
104 if (friend_not_valid(m, friendnumber)) { 102 if (!friend_is_valid(m, friendnumber)) {
105 return -1; 103 return -1;
106 } 104 }
107 105
@@ -140,7 +138,7 @@ void getaddress(const Messenger *m, uint8_t *address)
140 138
141static int send_online_packet(Messenger *m, int32_t friendnumber) 139static int send_online_packet(Messenger *m, int32_t friendnumber)
142{ 140{
143 if (friend_not_valid(m, friendnumber)) { 141 if (!friend_is_valid(m, friendnumber)) {
144 return 0; 142 return 0;
145 } 143 }
146 144
@@ -301,7 +299,7 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
301 299
302static int clear_receipts(Messenger *m, int32_t friendnumber) 300static int clear_receipts(Messenger *m, int32_t friendnumber)
303{ 301{
304 if (friend_not_valid(m, friendnumber)) { 302 if (!friend_is_valid(m, friendnumber)) {
305 return -1; 303 return -1;
306 } 304 }
307 305
@@ -320,7 +318,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
320 318
321static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id) 319static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
322{ 320{
323 if (friend_not_valid(m, friendnumber)) { 321 if (!friend_is_valid(m, friendnumber)) {
324 return -1; 322 return -1;
325 } 323 }
326 324
@@ -349,7 +347,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
349 */ 347 */
350static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number) 348static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number)
351{ 349{
352 if (friend_not_valid(m, friendnumber)) { 350 if (!friend_is_valid(m, friendnumber)) {
353 return -1; 351 return -1;
354 } 352 }
355 353
@@ -359,7 +357,7 @@ static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint
359 357
360static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata) 358static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
361{ 359{
362 if (friend_not_valid(m, friendnumber)) { 360 if (!friend_is_valid(m, friendnumber)) {
363 return -1; 361 return -1;
364 } 362 }
365 363
@@ -397,7 +395,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
397 */ 395 */
398int m_delfriend(Messenger *m, int32_t friendnumber) 396int m_delfriend(Messenger *m, int32_t friendnumber)
399{ 397{
400 if (friend_not_valid(m, friendnumber)) { 398 if (!friend_is_valid(m, friendnumber)) {
401 return -1; 399 return -1;
402 } 400 }
403 401
@@ -435,7 +433,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
435 433
436int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber) 434int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
437{ 435{
438 if (friend_not_valid(m, friendnumber)) { 436 if (!friend_is_valid(m, friendnumber)) {
439 return -1; 437 return -1;
440 } 438 }
441 439
@@ -463,7 +461,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
463 461
464int m_friend_exists(const Messenger *m, int32_t friendnumber) 462int m_friend_exists(const Messenger *m, int32_t friendnumber)
465{ 463{
466 if (friend_not_valid(m, friendnumber)) { 464 if (!friend_is_valid(m, friendnumber)) {
467 return 0; 465 return 0;
468 } 466 }
469 467
@@ -487,7 +485,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
487 return -5; 485 return -5;
488 } 486 }
489 487
490 if (friend_not_valid(m, friendnumber)) { 488 if (!friend_is_valid(m, friendnumber)) {
491 LOGGER_ERROR(m->log, "Friend number %d is invalid", friendnumber); 489 LOGGER_ERROR(m->log, "Friend number %d is invalid", friendnumber);
492 return -1; 490 return -1;
493 } 491 }
@@ -548,7 +546,7 @@ static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *n
548 */ 546 */
549int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length) 547int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
550{ 548{
551 if (friend_not_valid(m, friendnumber)) { 549 if (!friend_is_valid(m, friendnumber)) {
552 return -1; 550 return -1;
553 } 551 }
554 552
@@ -617,7 +615,7 @@ uint16_t getself_name(const Messenger *m, uint8_t *name)
617 */ 615 */
618int getname(const Messenger *m, int32_t friendnumber, uint8_t *name) 616int getname(const Messenger *m, int32_t friendnumber, uint8_t *name)
619{ 617{
620 if (friend_not_valid(m, friendnumber)) { 618 if (!friend_is_valid(m, friendnumber)) {
621 return -1; 619 return -1;
622 } 620 }
623 621
@@ -627,7 +625,7 @@ int getname(const Messenger *m, int32_t friendnumber, uint8_t *name)
627 625
628int m_get_name_size(const Messenger *m, int32_t friendnumber) 626int m_get_name_size(const Messenger *m, int32_t friendnumber)
629{ 627{
630 if (friend_not_valid(m, friendnumber)) { 628 if (!friend_is_valid(m, friendnumber)) {
631 return -1; 629 return -1;
632 } 630 }
633 631
@@ -689,7 +687,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
689 */ 687 */
690int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber) 688int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber)
691{ 689{
692 if (friend_not_valid(m, friendnumber)) { 690 if (!friend_is_valid(m, friendnumber)) {
693 return -1; 691 return -1;
694 } 692 }
695 693
@@ -701,7 +699,7 @@ int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber)
701 */ 699 */
702int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) 700int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
703{ 701{
704 if (friend_not_valid(m, friendnumber)) { 702 if (!friend_is_valid(m, friendnumber)) {
705 return -1; 703 return -1;
706 } 704 }
707 705
@@ -730,7 +728,7 @@ int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf)
730 728
731uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber) 729uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber)
732{ 730{
733 if (friend_not_valid(m, friendnumber)) { 731 if (!friend_is_valid(m, friendnumber)) {
734 return USERSTATUS_INVALID; 732 return USERSTATUS_INVALID;
735 } 733 }
736 734
@@ -750,7 +748,7 @@ uint8_t m_get_self_userstatus(const Messenger *m)
750 748
751uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber) 749uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber)
752{ 750{
753 if (friend_not_valid(m, friendnumber)) { 751 if (!friend_is_valid(m, friendnumber)) {
754 return UINT64_MAX; 752 return UINT64_MAX;
755 } 753 }
756 754
@@ -763,7 +761,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
763 return -1; 761 return -1;
764 } 762 }
765 763
766 if (friend_not_valid(m, friendnumber)) { 764 if (!friend_is_valid(m, friendnumber)) {
767 return -1; 765 return -1;
768 } 766 }
769 767
@@ -779,7 +777,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
779 777
780int m_get_istyping(const Messenger *m, int32_t friendnumber) 778int m_get_istyping(const Messenger *m, int32_t friendnumber)
781{ 779{
782 if (friend_not_valid(m, friendnumber)) { 780 if (!friend_is_valid(m, friendnumber)) {
783 return -1; 781 return -1;
784 } 782 }
785 783
@@ -804,7 +802,7 @@ static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t
804 802
805static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length) 803static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
806{ 804{
807 if (friend_not_valid(m, friendnumber)) { 805 if (!friend_is_valid(m, friendnumber)) {
808 return -1; 806 return -1;
809 } 807 }
810 808
@@ -952,7 +950,7 @@ static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status
952static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, 950static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
953 uint32_t length, uint8_t congestion_control) 951 uint32_t length, uint8_t congestion_control)
954{ 952{
955 if (friend_not_valid(m, friendnumber)) { 953 if (!friend_is_valid(m, friendnumber)) {
956 return 0; 954 return 0;
957 } 955 }
958 956
@@ -1033,7 +1031,7 @@ void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function)
1033 */ 1031 */
1034int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id) 1032int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id)
1035{ 1033{
1036 if (friend_not_valid(m, friendnumber)) { 1034 if (!friend_is_valid(m, friendnumber)) {
1037 return -1; 1035 return -1;
1038 } 1036 }
1039 1037
@@ -1082,7 +1080,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
1082static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, 1080static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type,
1083 uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) 1081 uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
1084{ 1082{
1085 if (friend_not_valid(m, friendnumber)) { 1083 if (!friend_is_valid(m, friendnumber)) {
1086 return 0; 1084 return 0;
1087 } 1085 }
1088 1086
@@ -1116,7 +1114,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
1116long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, 1114long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
1117 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) 1115 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
1118{ 1116{
1119 if (friend_not_valid(m, friendnumber)) { 1117 if (!friend_is_valid(m, friendnumber)) {
1120 return -1; 1118 return -1;
1121 } 1119 }
1122 1120
@@ -1195,7 +1193,7 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui
1195 */ 1193 */
1196int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control) 1194int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control)
1197{ 1195{
1198 if (friend_not_valid(m, friendnumber)) { 1196 if (!friend_is_valid(m, friendnumber)) {
1199 return -1; 1197 return -1;
1200 } 1198 }
1201 1199
@@ -1296,7 +1294,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
1296 */ 1294 */
1297int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position) 1295int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position)
1298{ 1296{
1299 if (friend_not_valid(m, friendnumber)) { 1297 if (!friend_is_valid(m, friendnumber)) {
1300 return -1; 1298 return -1;
1301 } 1299 }
1302 1300
@@ -1352,7 +1350,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
1352static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, 1350static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data,
1353 uint16_t length) 1351 uint16_t length)
1354{ 1352{
1355 if (friend_not_valid(m, friendnumber)) { 1353 if (!friend_is_valid(m, friendnumber)) {
1356 return -1; 1354 return -1;
1357 } 1355 }
1358 1356
@@ -1384,7 +1382,7 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u
1384int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, 1382int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
1385 uint16_t length) 1383 uint16_t length)
1386{ 1384{
1387 if (friend_not_valid(m, friendnumber)) { 1385 if (!friend_is_valid(m, friendnumber)) {
1388 return -1; 1386 return -1;
1389 } 1387 }
1390 1388
@@ -1455,7 +1453,7 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
1455 */ 1453 */
1456uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) 1454uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
1457{ 1455{
1458 if (friend_not_valid(m, friendnumber)) { 1456 if (!friend_is_valid(m, friendnumber)) {
1459 return 0; 1457 return 0;
1460 } 1458 }
1461 1459
@@ -1776,7 +1774,7 @@ static int m_handle_lossy_packet(void *object, int friend_num, const uint8_t *pa
1776{ 1774{
1777 Messenger *m = (Messenger *)object; 1775 Messenger *m = (Messenger *)object;
1778 1776
1779 if (friend_not_valid(m, friend_num)) { 1777 if (!friend_is_valid(m, friend_num)) {
1780 return 1; 1778 return 1;
1781 } 1779 }
1782 1780
@@ -1806,7 +1804,7 @@ void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb
1806int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function, 1804int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function,
1807 void *object) 1805 void *object)
1808{ 1806{
1809 if (friend_not_valid(m, friendnumber)) { 1807 if (!friend_is_valid(m, friendnumber)) {
1810 return -1; 1808 return -1;
1811 } 1809 }
1812 1810
@@ -1829,7 +1827,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lo
1829 */ 1827 */
1830int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) 1828int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
1831{ 1829{
1832 if (friend_not_valid(m, friendnumber)) { 1830 if (!friend_is_valid(m, friendnumber)) {
1833 return -1; 1831 return -1;
1834 } 1832 }
1835 1833
@@ -1859,7 +1857,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
1859{ 1857{
1860 Messenger *m = (Messenger *)object; 1858 Messenger *m = (Messenger *)object;
1861 1859
1862 if (friend_not_valid(m, friend_num)) { 1860 if (!friend_is_valid(m, friend_num)) {
1863 return -1; 1861 return -1;
1864 } 1862 }
1865 1863
@@ -1881,7 +1879,7 @@ void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_pack
1881 1879
1882int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) 1880int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
1883{ 1881{
1884 if (friend_not_valid(m, friendnumber)) { 1882 if (!friend_is_valid(m, friendnumber)) {
1885 return -1; 1883 return -1;
1886 } 1884 }
1887 1885
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 3dd8652e..adef3175 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -100,44 +100,44 @@ static int realloc_TCP_con(TCP_con **array, size_t num)
100} 100}
101 101
102 102
103/* return 1 if the connections_number is not valid. 103/**
104 * return 0 if the connections_number is valid. 104 * Return true if the connections_number is valid.
105 */ 105 */
106static bool connections_number_not_valid(const TCP_Connections *tcp_c, int connections_number) 106static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number)
107{ 107{
108 if ((unsigned int)connections_number >= tcp_c->connections_length) { 108 if ((unsigned int)connections_number >= tcp_c->connections_length) {
109 return 1; 109 return false;
110 } 110 }
111 111
112 if (tcp_c->connections == nullptr) { 112 if (tcp_c->connections == nullptr) {
113 return 1; 113 return false;
114 } 114 }
115 115
116 if (tcp_c->connections[connections_number].status == TCP_CONN_NONE) { 116 if (tcp_c->connections[connections_number].status == TCP_CONN_NONE) {
117 return 1; 117 return false;
118 } 118 }
119 119
120 return 0; 120 return true;
121} 121}
122 122
123/* return 1 if the tcp_connections_number is not valid. 123/**
124 * return 0 if the tcp_connections_number is valid. 124 * Return true if the tcp_connections_number is valid.
125 */ 125 */
126static bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int tcp_connections_number) 126static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
127{ 127{
128 if ((unsigned int)tcp_connections_number >= tcp_c->tcp_connections_length) { 128 if ((unsigned int)tcp_connections_number >= tcp_c->tcp_connections_length) {
129 return 1; 129 return false;
130 } 130 }
131 131
132 if (tcp_c->tcp_connections == nullptr) { 132 if (tcp_c->tcp_connections == nullptr) {
133 return 1; 133 return false;
134 } 134 }
135 135
136 if (tcp_c->tcp_connections[tcp_connections_number].status == TCP_CONN_NONE) { 136 if (tcp_c->tcp_connections[tcp_connections_number].status == TCP_CONN_NONE) {
137 return 1; 137 return false;
138 } 138 }
139 139
140 return 0; 140 return true;
141} 141}
142 142
143/* Create a new empty connection. 143/* Create a new empty connection.
@@ -199,7 +199,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
199 */ 199 */
200static int wipe_connection(TCP_Connections *tcp_c, int connections_number) 200static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
201{ 201{
202 if (connections_number_not_valid(tcp_c, connections_number)) { 202 if (!connections_number_is_valid(tcp_c, connections_number)) {
203 return -1; 203 return -1;
204 } 204 }
205 205
@@ -227,7 +227,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
227 */ 227 */
228static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number) 228static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number)
229{ 229{
230 if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) { 230 if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
231 return -1; 231 return -1;
232 } 232 }
233 233
@@ -250,7 +250,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
250 250
251static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number) 251static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
252{ 252{
253 if (connections_number_not_valid(tcp_c, connections_number)) { 253 if (!connections_number_is_valid(tcp_c, connections_number)) {
254 return nullptr; 254 return nullptr;
255 } 255 }
256 256
@@ -259,7 +259,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
259 259
260static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number) 260static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
261{ 261{
262 if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) { 262 if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
263 return nullptr; 263 return nullptr;
264 } 264 }
265 265
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index fb69b768..2851053b 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -174,23 +174,23 @@ DHT *nc_get_dht(const Net_Crypto *c)
174 return c->dht; 174 return c->dht;
175} 175}
176 176
177static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id) 177static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connection_id)
178{ 178{
179 if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) { 179 if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) {
180 return 1; 180 return false;
181 } 181 }
182 182
183 if (c->crypto_connections == nullptr) { 183 if (c->crypto_connections == nullptr) {
184 return 1; 184 return false;
185 } 185 }
186 186
187 const Crypto_Conn_State status = c->crypto_connections[crypt_connection_id].status; 187 const Crypto_Conn_State status = c->crypto_connections[crypt_connection_id].status;
188 188
189 if (status == CRYPTO_CONN_NO_CONNECTION || status == CRYPTO_CONN_FREE) { 189 if (status == CRYPTO_CONN_NO_CONNECTION || status == CRYPTO_CONN_FREE) {
190 return 1; 190 return false;
191 } 191 }
192 192
193 return 0; 193 return true;
194} 194}
195 195
196/* cookie timeout in seconds */ 196/* cookie timeout in seconds */
@@ -555,7 +555,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
555 555
556static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) 556static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
557{ 557{
558 if (crypt_connection_id_not_valid(c, crypt_connection_id)) { 558 if (!crypt_connection_id_is_valid(c, crypt_connection_id)) {
559 return nullptr; 559 return nullptr;
560 } 560 }
561 561
@@ -1858,7 +1858,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
1858static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key) 1858static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
1859{ 1859{
1860 for (uint32_t i = 0; i < c->crypto_connections_length; ++i) { 1860 for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
1861 if (crypt_connection_id_not_valid(c, i)) { 1861 if (!crypt_connection_id_is_valid(c, i)) {
1862 continue; 1862 continue;
1863 } 1863 }
1864 1864