diff options
-rw-r--r-- | testing/DHT_test.c | 2 | ||||
-rw-r--r-- | testing/misc_tools.c | 3 | ||||
-rw-r--r-- | testing/nTox.c | 32 | ||||
-rw-r--r-- | toxcore/DHT.c | 12 | ||||
-rw-r--r-- | toxcore/Messenger.c | 2 | ||||
-rw-r--r-- | toxcore/network.c | 17 | ||||
-rw-r--r-- | toxcore/util.c | 4 |
7 files changed, 37 insertions, 35 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index d76057c1..3cd1bce6 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -90,7 +90,7 @@ void print_friendlist(DHT *dht) | |||
90 | } | 90 | } |
91 | 91 | ||
92 | int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip); | 92 | int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip); |
93 | printf("\nIP: %s:%u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port)); | 93 | printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip), ntohs(p_ip.port), friendok); |
94 | 94 | ||
95 | printf("\nCLIENTS IN LIST:\n\n"); | 95 | printf("\nCLIENTS IN LIST:\n\n"); |
96 | 96 | ||
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 81f5ed8a..d05c88f6 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -36,10 +36,9 @@ | |||
36 | /* TODO: rewrite */ | 36 | /* TODO: rewrite */ |
37 | unsigned char *hex_string_to_bin(char hex_string[]) | 37 | unsigned char *hex_string_to_bin(char hex_string[]) |
38 | { | 38 | { |
39 | size_t len = strlen(hex_string); | 39 | size_t i, len = strlen(hex_string); |
40 | unsigned char *val = malloc(len); | 40 | unsigned char *val = malloc(len); |
41 | char *pos = hex_string; | 41 | char *pos = hex_string; |
42 | int i; | ||
43 | 42 | ||
44 | for (i = 0; i < len; ++i, pos += 2) | 43 | for (i = 0; i < len; ++i, pos += 2) |
45 | sscanf(pos, "%2hhx", &val[i]); | 44 | sscanf(pos, "%2hhx", &val[i]); |
diff --git a/testing/nTox.c b/testing/nTox.c index 029d62b4..e87b4b83 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -133,10 +133,10 @@ void get_id(Tox *m, char *data) | |||
133 | { | 133 | { |
134 | sprintf(data, "[i] ID: "); | 134 | sprintf(data, "[i] ID: "); |
135 | int offset = strlen(data); | 135 | int offset = strlen(data); |
136 | int i = 0; | ||
137 | uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; | 136 | uint8_t address[TOX_FRIEND_ADDRESS_SIZE]; |
138 | tox_getaddress(m, address); | 137 | tox_getaddress(m, address); |
139 | 138 | ||
139 | uint32_t i = 0; | ||
140 | for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) { | 140 | for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) { |
141 | sprintf(data + 2 * i + offset, "%02X ", address[i]); | 141 | sprintf(data + 2 * i + offset, "%02X ", address[i]); |
142 | } | 142 | } |
@@ -275,13 +275,13 @@ void line_eval(Tox *m, char *line) | |||
275 | 275 | ||
276 | char numstring[len - 3]; | 276 | char numstring[len - 3]; |
277 | char message[len - 3]; | 277 | char message[len - 3]; |
278 | int i; | 278 | uint32_t i; |
279 | 279 | ||
280 | for (i = 0; i < len; i++) { | 280 | for (i = 0; i < len; i++) { |
281 | if (line[i + 3] != ' ') { | 281 | if (line[i + 3] != ' ') { |
282 | numstring[i] = line[i + 3]; | 282 | numstring[i] = line[i + 3]; |
283 | } else { | 283 | } else { |
284 | int j; | 284 | uint32_t j; |
285 | 285 | ||
286 | for (j = (i + 1); j < (len + 1); j++) | 286 | for (j = (i + 1); j < (len + 1); j++) |
287 | message[j - i - 1] = line[j + 3]; | 287 | message[j - i - 1] = line[j + 3]; |
@@ -299,8 +299,7 @@ void line_eval(Tox *m, char *line) | |||
299 | } | 299 | } |
300 | } else if (inpt_command == 'n') { | 300 | } else if (inpt_command == 'n') { |
301 | uint8_t name[TOX_MAX_NAME_LENGTH]; | 301 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
302 | int i = 0; | 302 | size_t i, len = strlen(line); |
303 | size_t len = strlen(line); | ||
304 | 303 | ||
305 | for (i = 3; i < len; i++) { | 304 | for (i = 3; i < len; i++) { |
306 | if (line[i] == 0 || line[i] == '\n') break; | 305 | if (line[i] == 0 || line[i] == '\n') break; |
@@ -317,8 +316,7 @@ void line_eval(Tox *m, char *line) | |||
317 | print_friendlist(m); | 316 | print_friendlist(m); |
318 | } else if (inpt_command == 's') { | 317 | } else if (inpt_command == 's') { |
319 | uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; | 318 | uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; |
320 | int i = 0; | 319 | size_t i, len = strlen(line); |
321 | size_t len = strlen(line); | ||
322 | 320 | ||
323 | for (i = 3; i < len; i++) { | 321 | for (i = 3; i < len; i++) { |
324 | if (line[i] == 0 || line[i] == '\n') break; | 322 | if (line[i] == 0 || line[i] == '\n') break; |
@@ -399,8 +397,7 @@ void line_eval(Tox *m, char *line) | |||
399 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | 397 | void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) |
400 | { | 398 | { |
401 | strcpy(output, input); | 399 | strcpy(output, input); |
402 | size_t len = strlen(output); | 400 | size_t i, len = strlen(output); |
403 | int i = 0; | ||
404 | 401 | ||
405 | for (i = line_width; i < len; i = i + line_width) { | 402 | for (i = line_width; i < len; i = i + line_width) { |
406 | while (output[i] != ' ' && i != 0) { | 403 | while (output[i] != ' ' && i != 0) { |
@@ -415,9 +412,8 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) | |||
415 | 412 | ||
416 | int count_lines(char *string) | 413 | int count_lines(char *string) |
417 | { | 414 | { |
418 | size_t len = strlen(string); | 415 | size_t i, len = strlen(string); |
419 | int count = 1; | 416 | int count = 1; |
420 | int i; | ||
421 | 417 | ||
422 | for (i = 0; i < len; i++) { | 418 | for (i = 0; i < len; i++) { |
423 | if (string[i] == '\n') | 419 | if (string[i] == '\n') |
@@ -511,7 +507,7 @@ static char *data_file_name = NULL; | |||
511 | static int load_data(Tox *m) | 507 | static int load_data(Tox *m) |
512 | { | 508 | { |
513 | FILE *data_file = fopen(data_file_name, "r"); | 509 | FILE *data_file = fopen(data_file_name, "r"); |
514 | int size = 0; | 510 | size_t size = 0; |
515 | if (data_file) { | 511 | if (data_file) { |
516 | fseek(data_file, 0, SEEK_END); | 512 | fseek(data_file, 0, SEEK_END); |
517 | size = ftell(data_file); | 513 | size = ftell(data_file); |
@@ -520,6 +516,7 @@ static int load_data(Tox *m) | |||
520 | uint8_t data[size]; | 516 | uint8_t data[size]; |
521 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { | 517 | if (fread(data, sizeof(uint8_t), size, data_file) != size) { |
522 | fputs("[!] could not read data file!\n", stderr); | 518 | fputs("[!] could not read data file!\n", stderr); |
519 | fclose(data_file); | ||
523 | return 0; | 520 | return 0; |
524 | } | 521 | } |
525 | 522 | ||
@@ -545,19 +542,22 @@ static int save_data(Tox *m) | |||
545 | return 0; | 542 | return 0; |
546 | } | 543 | } |
547 | 544 | ||
548 | int size = tox_size(m); | 545 | int res = 1; |
546 | size_t size = tox_size(m); | ||
549 | uint8_t data[size]; | 547 | uint8_t data[size]; |
550 | tox_save(m, data); | 548 | tox_save(m, data); |
551 | 549 | ||
552 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { | 550 | if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { |
553 | fputs("[!] could not write data file (1)!", stderr); | 551 | fputs("[!] could not write data file (1)!", stderr); |
554 | return 0; | 552 | res = 0; |
555 | } | 553 | } |
556 | 554 | ||
557 | if (fclose(data_file) < 0) { | 555 | if (fclose(data_file) < 0) { |
558 | perror("[!] could not write data file (2)"); | 556 | perror("[!] could not write data file (2)"); |
559 | return 0; | 557 | res = 0; |
560 | } | 558 | } |
559 | |||
560 | return res; | ||
561 | } | 561 | } |
562 | 562 | ||
563 | static int load_data_or_init(Tox *m, char *path) | 563 | static int load_data_or_init(Tox *m, char *path) |
@@ -667,7 +667,7 @@ int main(int argc, char *argv[]) | |||
667 | nodelay(stdscr, TRUE); | 667 | nodelay(stdscr, TRUE); |
668 | 668 | ||
669 | new_lines("[i] change username with /n"); | 669 | new_lines("[i] change username with /n"); |
670 | char name[TOX_MAX_NAME_LENGTH]; | 670 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
671 | uint16_t namelen = tox_getselfname(m, name, sizeof(name)); | 671 | uint16_t namelen = tox_getselfname(m, name, sizeof(name)); |
672 | if (namelen > 0) { | 672 | if (namelen > 0) { |
673 | char whoami[128 + TOX_MAX_NAME_LENGTH]; | 673 | char whoami[128 + TOX_MAX_NAME_LENGTH]; |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 2f7b2263..db9bfe3c 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -200,8 +200,8 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod | |||
200 | time_t timestamp, int *num_nodes_ptr) | 200 | time_t timestamp, int *num_nodes_ptr) |
201 | { | 201 | { |
202 | int num_nodes = *num_nodes_ptr; | 202 | int num_nodes = *num_nodes_ptr; |
203 | int i, tout, inlist, ipv46x, j, closest; | 203 | int tout, inlist, ipv46x, j, closest; |
204 | 204 | uint32_t i; | |
205 | for (i = 0; i < client_list_length; i++) { | 205 | for (i = 0; i < client_list_length; i++) { |
206 | Client_data *client = &client_list[i]; | 206 | Client_data *client = &client_list[i]; |
207 | tout = is_timeout(timestamp, client->timestamp, BAD_NODE_TIMEOUT); | 207 | tout = is_timeout(timestamp, client->timestamp, BAD_NODE_TIMEOUT); |
@@ -726,10 +726,10 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3 | |||
726 | #ifdef TOX_ENABLE_IPV6 | 726 | #ifdef TOX_ENABLE_IPV6 |
727 | Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id)); | 727 | Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id)); |
728 | 728 | ||
729 | int num_nodes_ok = 0; | 729 | uint32_t num_nodes_ok = 0; |
730 | 730 | ||
731 | for (i = 0; i < num_nodes; i++) | 731 | for (i = 0; i < num_nodes; i++) |
732 | if ((nodes4_list[i].ip_port.ip.uint32 != 0) && (nodes4_list[i].ip_port.ip.uint32 != ~0)) { | 732 | if ((nodes4_list[i].ip_port.ip.uint32 != 0) && (nodes4_list[i].ip_port.ip.uint32 != (uint32_t)~0)) { |
733 | memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE); | 733 | memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE); |
734 | nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET; | 734 | nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET; |
735 | nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32; | 735 | nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32; |
@@ -1477,14 +1477,14 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
1477 | int DHT_load(DHT *dht, uint8_t *data, uint32_t size) | 1477 | int DHT_load(DHT *dht, uint8_t *data, uint32_t size) |
1478 | { | 1478 | { |
1479 | if (size < sizeof(dht->close_clientlist)) { | 1479 | if (size < sizeof(dht->close_clientlist)) { |
1480 | fprintf(stderr, "DHT_load: Expected at least %lu bytes, got %u.\n", sizeof(dht->close_clientlist), size); | 1480 | fprintf(stderr, "DHT_load: Expected at least %u bytes, got %u.\n", sizeof(dht->close_clientlist), size); |
1481 | return -1; | 1481 | return -1; |
1482 | } | 1482 | } |
1483 | 1483 | ||
1484 | uint32_t friendlistsize = size - sizeof(dht->close_clientlist); | 1484 | uint32_t friendlistsize = size - sizeof(dht->close_clientlist); |
1485 | 1485 | ||
1486 | if (friendlistsize % sizeof(DHT_Friend) != 0) { | 1486 | if (friendlistsize % sizeof(DHT_Friend) != 0) { |
1487 | fprintf(stderr, "DHT_load: Expected a multiple of %lu, got %u.\n", sizeof(DHT_Friend), friendlistsize); | 1487 | fprintf(stderr, "DHT_load: Expected a multiple of %u, got %u.\n", sizeof(DHT_Friend), friendlistsize); |
1488 | return -1; | 1488 | return -1; |
1489 | } | 1489 | } |
1490 | 1490 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index eb18e3a3..c46e3938 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1220,7 +1220,7 @@ void doInbound(Messenger *m) | |||
1220 | } | 1220 | } |
1221 | 1221 | ||
1222 | #ifdef LOGGING | 1222 | #ifdef LOGGING |
1223 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60 | 1223 | #define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL |
1224 | static time_t lastdump = 0; | 1224 | static time_t lastdump = 0; |
1225 | static char IDString[CLIENT_ID_SIZE * 2 + 1]; | 1225 | static char IDString[CLIENT_ID_SIZE * 2 + 1]; |
1226 | static char *ID2String(uint8_t *client_id) | 1226 | static char *ID2String(uint8_t *client_id) |
diff --git a/toxcore/network.c b/toxcore/network.c index 4b6dc3be..4f6b0aae 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -154,14 +154,15 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t | |||
154 | #ifdef WIN32 | 154 | #ifdef WIN32 |
155 | int addrlen = sizeof(addr); | 155 | int addrlen = sizeof(addr); |
156 | #else | 156 | #else |
157 | uint32_t addrlen = sizeof(addr); | 157 | socklen_t addrlen = sizeof(addr); |
158 | #endif | 158 | #endif |
159 | (*(int32_t *)length) = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); | 159 | *length = 0; |
160 | int fail_or_len = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen); | ||
160 | 161 | ||
161 | if (*(int32_t *)length <= 0) { | 162 | if (fail_or_len <= 0) { |
162 | #ifdef LOGGING | 163 | #ifdef LOGGING |
163 | 164 | ||
164 | if ((length < 0) && (errno != EWOULDBLOCK)) { | 165 | if ((fail_or_len < 0) && (errno != EWOULDBLOCK)) { |
165 | sprintf(logbuffer, "Unexpected error reading from socket: %u, %s\n", errno, strerror(errno)); | 166 | sprintf(logbuffer, "Unexpected error reading from socket: %u, %s\n", errno, strerror(errno)); |
166 | loglog(logbuffer); | 167 | loglog(logbuffer); |
167 | } | 168 | } |
@@ -170,6 +171,8 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t | |||
170 | return -1; /* Nothing received or empty packet. */ | 171 | return -1; /* Nothing received or empty packet. */ |
171 | } | 172 | } |
172 | 173 | ||
174 | *length = (uint32_t)fail_or_len; | ||
175 | |||
173 | #ifdef TOX_ENABLE_IPV6 | 176 | #ifdef TOX_ENABLE_IPV6 |
174 | 177 | ||
175 | if (addr.ss_family == AF_INET) { | 178 | if (addr.ss_family == AF_INET) { |
@@ -863,15 +866,15 @@ static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *i | |||
863 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), errno, | 866 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), errno, |
864 | strerror(errno), buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, | 867 | strerror(errno), buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, |
865 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); | 868 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); |
866 | else if ((res > 0) && (res <= buflen)) | 869 | else if ((res > 0) && ((size_t)res <= buflen)) |
867 | snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x\n", | 870 | snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x\n", |
868 | buffer[0], message, res < 999 ? res : 999, res < buflen ? '<' : '=', | 871 | buffer[0], message, res < 999 ? res : 999, (size_t)res < buflen ? '<' : '=', |
869 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0, | 872 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0, |
870 | "OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, | 873 | "OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, |
871 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); | 874 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); |
872 | else /* empty or overwrite */ | 875 | else /* empty or overwrite */ |
873 | snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x\n", | 876 | snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x\n", |
874 | buffer[0], message, res, !res ? '0' : '>', buflen, | 877 | buffer[0], message, res, !res ? '!' : '>', buflen, |
875 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0, | 878 | ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0, |
876 | "OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, | 879 | "OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0, |
877 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); | 880 | buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0); |
diff --git a/toxcore/util.c b/toxcore/util.c index 8960fe36..e1c46ee5 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -52,14 +52,14 @@ void loginit(uint16_t port) | |||
52 | if (logfile) | 52 | if (logfile) |
53 | fclose(logfile); | 53 | fclose(logfile); |
54 | 54 | ||
55 | sprintf(logbuffer, "%u-%u.log", ntohs(port), now()); | 55 | sprintf(logbuffer, "%u-%u.log", ntohs(port), (uint32_t)now()); |
56 | logfile = fopen(logbuffer, "w"); | 56 | logfile = fopen(logbuffer, "w"); |
57 | starttime = now(); | 57 | starttime = now(); |
58 | }; | 58 | }; |
59 | void loglog(char *text) | 59 | void loglog(char *text) |
60 | { | 60 | { |
61 | if (logfile) { | 61 | if (logfile) { |
62 | fprintf(logfile, "%4u ", now() - starttime); | 62 | fprintf(logfile, "%4u ", (uint32_t)(now() - starttime)); |
63 | fprintf(logfile, text); | 63 | fprintf(logfile, text); |
64 | fflush(logfile); | 64 | fflush(logfile); |
65 | } | 65 | } |