summaryrefslogtreecommitdiff
path: root/toxcore/TCP_server.c
diff options
context:
space:
mode:
authorzugz (tox) <mbays+tox@sdf.org>2020-02-28 00:00:00 +0000
committerzugz (tox) <mbays+tox@sdf.org>2020-03-14 00:00:02 +0000
commitc644ef76810f8db61bce3f52d36a1a6a25e47683 (patch)
tree1a4c5ed13f1a3450e3a005746ba6bb0d1af7beaf /toxcore/TCP_server.c
parente6714909898d7e5fe6b35b6d109e584e6c5858b0 (diff)
use -1 rather than ~0 in unsigned integer types
Using ~0 involves a bitwise operation on int, so depends on the internal representation of signed integers.
Diffstat (limited to 'toxcore/TCP_server.c')
-rw-r--r--toxcore/TCP_server.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 23b95940..086fe3d3 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -288,7 +288,7 @@ static int del_accepted(TCP_Server *tcp_server, int index)
288 * 288 *
289 * return length on success 289 * return length on success
290 * return 0 if nothing has been read from socket. 290 * return 0 if nothing has been read from socket.
291 * return ~0 on failure. 291 * return -1 on failure.
292 */ 292 */
293uint16_t read_TCP_length(Socket sock) 293uint16_t read_TCP_length(Socket sock)
294{ 294{
@@ -306,7 +306,7 @@ uint16_t read_TCP_length(Socket sock)
306 length = net_ntohs(length); 306 length = net_ntohs(length);
307 307
308 if (length > MAX_PACKET_SIZE) { 308 if (length > MAX_PACKET_SIZE) {
309 return ~0; 309 return -1;
310 } 310 }
311 311
312 return length; 312 return length;
@@ -348,7 +348,7 @@ int read_packet_TCP_secure_connection(Socket sock, uint16_t *next_packet_length,
348 if (*next_packet_length == 0) { 348 if (*next_packet_length == 0) {
349 uint16_t len = read_TCP_length(sock); 349 uint16_t len = read_TCP_length(sock);
350 350
351 if (len == (uint16_t)~0) { 351 if (len == (uint16_t) -1) {
352 return -1; 352 return -1;
353 } 353 }
354 354
@@ -684,7 +684,7 @@ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id)
684static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key) 684static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
685{ 685{
686 uint32_t i; 686 uint32_t i;
687 uint32_t index = ~0; 687 uint32_t index = -1;
688 TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id]; 688 TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id];
689 689
690 /* If person tries to cennect to himself we deny the request*/ 690 /* If person tries to cennect to himself we deny the request*/
@@ -705,12 +705,12 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
705 705
706 return 0; 706 return 0;
707 } 707 }
708 } else if (index == (uint32_t)~0) { 708 } else if (index == (uint32_t) -1) {
709 index = i; 709 index = i;
710 } 710 }
711 } 711 }
712 712
713 if (index == (uint32_t)~0) { 713 if (index == (uint32_t) -1) {
714 if (send_routing_response(con, 0, public_key) == -1) { 714 if (send_routing_response(con, 0, public_key) == -1) {
715 return -1; 715 return -1;
716 } 716 }
@@ -733,7 +733,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
733 int other_index = get_TCP_connection_index(tcp_server, public_key); 733 int other_index = get_TCP_connection_index(tcp_server, public_key);
734 734
735 if (other_index != -1) { 735 if (other_index != -1) {
736 uint32_t other_id = ~0; 736 uint32_t other_id = -1;
737 TCP_Secure_Connection *other_conn = &tcp_server->accepted_connection_array[other_index]; 737 TCP_Secure_Connection *other_conn = &tcp_server->accepted_connection_array[other_index];
738 738
739 for (i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { 739 for (i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) {
@@ -744,7 +744,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
744 } 744 }
745 } 745 }
746 746
747 if (other_id != (uint32_t)~0) { 747 if (other_id != (uint32_t) -1) {
748 con->connections[index].status = 2; 748 con->connections[index].status = 2;
749 con->connections[index].index = other_index; 749 con->connections[index].index = other_index;
750 con->connections[index].other_id = other_id; 750 con->connections[index].other_id = other_id;