summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/messenger_test.c8
-rw-r--r--auto_tests/network_test.c308
-rw-r--r--testing/nTox.c10
-rw-r--r--toxcore/DHT.c2
-rw-r--r--toxcore/Messenger.c4
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/group_chats.c4
-rw-r--r--toxcore/group_chats.h4
-rw-r--r--toxcore/net_crypto.c4
-rw-r--r--toxcore/tox.c2
-rw-r--r--toxcore/tox.h2
-rw-r--r--toxcore/util.h2
12 files changed, 184 insertions, 168 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index dc1625a3..f749f6cb 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -239,12 +239,14 @@ START_TEST(test_dht_state_saveloadsave)
239 memset(buffer, 0xCD, extra); 239 memset(buffer, 0xCD, extra);
240 memset(buffer + extra + size, 0xCD, extra); 240 memset(buffer + extra + size, 0xCD, extra);
241 DHT_save(m->dht, buffer + extra); 241 DHT_save(m->dht, buffer + extra);
242 for(i = 0; i < extra; i++) { 242
243 for (i = 0; i < extra; i++) {
243 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i); 244 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", i);
244 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i); 245 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", i);
245 } 246 }
246 247
247 int res = DHT_load_new(m->dht, buffer + extra, size); 248 int res = DHT_load_new(m->dht, buffer + extra, size);
249
248 if (res == -1) 250 if (res == -1)
249 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1"); 251 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
250 else { 252 else {
@@ -279,12 +281,14 @@ START_TEST(test_messenger_state_saveloadsave)
279 memset(buffer, 0xCD, extra); 281 memset(buffer, 0xCD, extra);
280 memset(buffer + extra + size, 0xCD, extra); 282 memset(buffer + extra + size, 0xCD, extra);
281 Messenger_save(m, buffer + extra); 283 Messenger_save(m, buffer + extra);
282 for(i = 0; i < extra; i++) { 284
285 for (i = 0; i < extra; i++) {
283 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from Messenger_save() @%u", i); 286 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from Messenger_save() @%u", i);
284 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from Messenger_save() @%u", i); 287 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from Messenger_save() @%u", i);
285 } 288 }
286 289
287 int res = Messenger_load(m, buffer + extra, size); 290 int res = Messenger_load(m, buffer + extra, size);
291
288 if (res == -1) 292 if (res == -1)
289 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1"); 293 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
290 else { 294 else {
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c
index 593b1f40..8d2a12d9 100644
--- a/auto_tests/network_test.c
+++ b/auto_tests/network_test.c
@@ -1,154 +1,154 @@
1#ifdef HAVE_CONFIG_H 1#ifdef HAVE_CONFIG_H
2#include "config.h" 2#include "config.h"
3#endif 3#endif
4 4
5#include <sys/types.h> 5#include <sys/types.h>
6#include <stdint.h> 6#include <stdint.h>
7#include <string.h> 7#include <string.h>
8#include <check.h> 8#include <check.h>
9#include <stdlib.h> 9#include <stdlib.h>
10#include <time.h> 10#include <time.h>
11 11
12#include "../toxcore/network.h" 12#include "../toxcore/network.h"
13 13
14START_TEST(test_addr_resolv_localhost) 14START_TEST(test_addr_resolv_localhost)
15{ 15{
16#ifdef __CYGWIN__ 16#ifdef __CYGWIN__
17 /* force initialization of network stack 17 /* force initialization of network stack
18 * normally this should happen automatically 18 * normally this should happen automatically
19 * cygwin doesn't do it for every network related function though 19 * cygwin doesn't do it for every network related function though
20 * e.g. not for getaddrinfo... */ 20 * e.g. not for getaddrinfo... */
21 socket(0, 0, 0); 21 socket(0, 0, 0);
22 errno = 0; 22 errno = 0;
23#endif 23#endif
24 24
25 const char localhost[] = "localhost"; 25 const char localhost[] = "localhost";
26 26
27 IP ip; 27 IP ip;
28 ip_init(&ip, 0); 28 ip_init(&ip, 0);
29 29
30 int res = addr_resolve(localhost, &ip, NULL); 30 int res = addr_resolve(localhost, &ip, NULL);
31 31
32 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); 32 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
33 33
34 if (res > 0) { 34 if (res > 0) {
35 ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family); 35 ck_assert_msg(ip.family == AF_INET, "Expected family AF_INET, got %u.", ip.family);
36 ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr)); 36 ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr));
37 } 37 }
38 38
39 ip_init(&ip, 1); 39 ip_init(&ip, 1);
40 res = addr_resolve(localhost, &ip, NULL); 40 res = addr_resolve(localhost, &ip, NULL);
41 41
42 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); 42 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
43 43
44 if (res > 0) { 44 if (res > 0) {
45 ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); 45 ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
46 ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); 46 ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
47 } 47 }
48 48
49 ip_init(&ip, 1); 49 ip_init(&ip, 1);
50 ip.family = AF_UNSPEC; 50 ip.family = AF_UNSPEC;
51 IP extra; 51 IP extra;
52 ip_reset(&extra); 52 ip_reset(&extra);
53 res = addr_resolve(localhost, &ip, &extra); 53 res = addr_resolve(localhost, &ip, &extra);
54 54
55 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); 55 ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
56 56
57 if (res > 0) { 57 if (res > 0) {
58 ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); 58 ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
59 ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); 59 ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
60 60
61 ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); 61 ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family);
62 ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); 62 ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr));
63 } 63 }
64} 64}
65END_TEST 65END_TEST
66 66
67START_TEST(test_ip_equal) 67START_TEST(test_ip_equal)
68{ 68{
69 int res; 69 int res;
70 IP ip1, ip2; 70 IP ip1, ip2;
71 ip_reset(&ip1); 71 ip_reset(&ip1);
72 ip_reset(&ip2); 72 ip_reset(&ip2);
73 73
74 res = ip_equal(NULL, NULL); 74 res = ip_equal(NULL, NULL);
75 ck_assert_msg(res == 0, "ip_equal(NULL, NULL): expected result 0, got %u.", res); 75 ck_assert_msg(res == 0, "ip_equal(NULL, NULL): expected result 0, got %u.", res);
76 76
77 res = ip_equal(&ip1, NULL); 77 res = ip_equal(&ip1, NULL);
78 ck_assert_msg(res == 0, "ip_equal(PTR, NULL): expected result 0, got %u.", res); 78 ck_assert_msg(res == 0, "ip_equal(PTR, NULL): expected result 0, got %u.", res);
79 79
80 res = ip_equal(NULL, &ip1); 80 res = ip_equal(NULL, &ip1);
81 ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res); 81 ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res);
82 82
83 ip1.family = AF_INET; 83 ip1.family = AF_INET;
84 ip1.ip4.uint32 = htonl(0x7F000001); 84 ip1.ip4.uint32 = htonl(0x7F000001);
85 85
86 res = ip_equal(&ip1, &ip2); 86 res = ip_equal(&ip1, &ip2);
87 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_UNSPEC, 0} ): expected result 0, got %u.", res); 87 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_UNSPEC, 0} ): expected result 0, got %u.", res);
88 88
89 ip2.family = AF_INET; 89 ip2.family = AF_INET;
90 ip2.ip4.uint32 = htonl(0x7F000001); 90 ip2.ip4.uint32 = htonl(0x7F000001);
91 91
92 res = ip_equal(&ip1, &ip2); 92 res = ip_equal(&ip1, &ip2);
93 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.1} ): expected result != 0, got 0."); 93 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.1} ): expected result != 0, got 0.");
94 94
95 ip2.ip4.uint32 = htonl(0x7F000002); 95 ip2.ip4.uint32 = htonl(0x7F000002);
96 96
97 res = ip_equal(&ip1, &ip2); 97 res = ip_equal(&ip1, &ip2);
98 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.2} ): expected result 0, got %u.", res); 98 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET, 127.0.0.2} ): expected result 0, got %u.", res);
99 99
100 ip2.family = AF_INET6; 100 ip2.family = AF_INET6;
101 ip2.ip6.uint32[0] = 0; 101 ip2.ip6.uint32[0] = 0;
102 ip2.ip6.uint32[1] = 0; 102 ip2.ip6.uint32[1] = 0;
103 ip2.ip6.uint32[2] = htonl(0xFFFF); 103 ip2.ip6.uint32[2] = htonl(0xFFFF);
104 ip2.ip6.uint32[3] = htonl(0x7F000001); 104 ip2.ip6.uint32[3] = htonl(0x7F000001);
105 105
106 ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6) != 0, "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0."); 106 ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6) != 0, "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0.");
107 107
108 res = ip_equal(&ip1, &ip2); 108 res = ip_equal(&ip1, &ip2);
109 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0."); 109 ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0.");
110 110
111 memcpy(&ip2.ip6, &in6addr_loopback, sizeof(IP6)); 111 memcpy(&ip2.ip6, &in6addr_loopback, sizeof(IP6));
112 res = ip_equal(&ip1, &ip2); 112 res = ip_equal(&ip1, &ip2);
113 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::1} ): expected result 0, got %u.", res); 113 ck_assert_msg(res == 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::1} ): expected result 0, got %u.", res);
114 114
115 memcpy(&ip1, &ip2, sizeof(IP)); 115 memcpy(&ip1, &ip2, sizeof(IP));
116 res = ip_equal(&ip1, &ip2); 116 res = ip_equal(&ip1, &ip2);
117 ck_assert_msg(res != 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::1} ): expected result != 0, got 0."); 117 ck_assert_msg(res != 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::1} ): expected result != 0, got 0.");
118 118
119 ip2.ip6.uint8[15]++; 119 ip2.ip6.uint8[15]++;
120 res = ip_equal(&ip1, &ip2); 120 res = ip_equal(&ip1, &ip2);
121 ck_assert_msg(res == 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::2} ): expected result 0, got %res.", res); 121 ck_assert_msg(res == 0, "ip_equal( {AF_INET6, ::1}, {AF_INET6, ::2} ): expected result 0, got %res.", res);
122} 122}
123END_TEST 123END_TEST
124 124
125#define DEFTESTCASE(NAME) \ 125#define DEFTESTCASE(NAME) \
126 TCase *NAME = tcase_create(#NAME); \ 126 TCase *NAME = tcase_create(#NAME); \
127 tcase_add_test(NAME, test_##NAME); \ 127 tcase_add_test(NAME, test_##NAME); \
128 suite_add_tcase(s, NAME); 128 suite_add_tcase(s, NAME);
129 129
130Suite *network_suite(void) 130Suite *network_suite(void)
131{ 131{
132 Suite *s = suite_create("Network"); 132 Suite *s = suite_create("Network");
133 133
134 DEFTESTCASE(addr_resolv_localhost); 134 DEFTESTCASE(addr_resolv_localhost);
135 DEFTESTCASE(ip_equal); 135 DEFTESTCASE(ip_equal);
136 136
137 return s; 137 return s;
138} 138}
139 139
140int main(int argc, char *argv[]) 140int main(int argc, char *argv[])
141{ 141{
142 srand((unsigned int) time(NULL)); 142 srand((unsigned int) time(NULL));
143 143
144 Suite *network = network_suite(); 144 Suite *network = network_suite();
145 SRunner *test_runner = srunner_create(network); 145 SRunner *test_runner = srunner_create(network);
146 int number_failed = 0; 146 int number_failed = 0;
147 147
148 srunner_run_all(test_runner, CK_NORMAL); 148 srunner_run_all(test_runner, CK_NORMAL);
149 number_failed = srunner_ntests_failed(test_runner); 149 number_failed = srunner_ntests_failed(test_runner);
150 150
151 srunner_free(test_runner); 151 srunner_free(test_runner);
152 152
153 return number_failed; 153 return number_failed;
154} 154}
diff --git a/testing/nTox.c b/testing/nTox.c
index cf79b3c4..2e394528 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -137,6 +137,7 @@ void get_id(Tox *m, char *data)
137 tox_getaddress(m, address); 137 tox_getaddress(m, address);
138 138
139 uint32_t i = 0; 139 uint32_t i = 0;
140
140 for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) { 141 for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
141 sprintf(data + 2 * i + offset, "%02X ", address[i]); 142 sprintf(data + 2 * i + offset, "%02X ", address[i]);
142 } 143 }
@@ -257,9 +258,9 @@ void line_eval(Tox *m, char *line)
257 if (num >= 0) { 258 if (num >= 0) {
258 sprintf(numstring, "[i] Added friend as %d.", num); 259 sprintf(numstring, "[i] Added friend as %d.", num);
259 save_data(m); 260 save_data(m);
260 } 261 } else
261 else
262 sprintf(numstring, "[i] Unknown error %i.", num); 262 sprintf(numstring, "[i] Unknown error %i.", num);
263
263 break; 264 break;
264 } 265 }
265 266
@@ -508,12 +509,14 @@ static int load_data(Tox *m)
508{ 509{
509 FILE *data_file = fopen(data_file_name, "r"); 510 FILE *data_file = fopen(data_file_name, "r");
510 size_t size = 0; 511 size_t size = 0;
512
511 if (data_file) { 513 if (data_file) {
512 fseek(data_file, 0, SEEK_END); 514 fseek(data_file, 0, SEEK_END);
513 size = ftell(data_file); 515 size = ftell(data_file);
514 rewind(data_file); 516 rewind(data_file);
515 517
516 uint8_t data[size]; 518 uint8_t data[size];
519
517 if (fread(data, sizeof(uint8_t), size, data_file) != size) { 520 if (fread(data, sizeof(uint8_t), size, data_file) != size) {
518 fputs("[!] could not read data file!\n", stderr); 521 fputs("[!] could not read data file!\n", stderr);
519 fclose(data_file); 522 fclose(data_file);
@@ -537,6 +540,7 @@ static int load_data(Tox *m)
537static int save_data(Tox *m) 540static int save_data(Tox *m)
538{ 541{
539 FILE *data_file = fopen(data_file_name, "w"); 542 FILE *data_file = fopen(data_file_name, "w");
543
540 if (!data_file) { 544 if (!data_file) {
541 perror("[!] load_key"); 545 perror("[!] load_key");
542 return 0; 546 return 0;
@@ -563,6 +567,7 @@ static int save_data(Tox *m)
563static int load_data_or_init(Tox *m, char *path) 567static int load_data_or_init(Tox *m, char *path)
564{ 568{
565 data_file_name = path; 569 data_file_name = path;
570
566 if (load_data(m)) 571 if (load_data(m))
567 return 1; 572 return 1;
568 573
@@ -671,6 +676,7 @@ int main(int argc, char *argv[])
671 new_lines("[i] change username with /n"); 676 new_lines("[i] change username with /n");
672 uint8_t name[TOX_MAX_NAME_LENGTH]; 677 uint8_t name[TOX_MAX_NAME_LENGTH];
673 uint16_t namelen = tox_getselfname(m, name, sizeof(name)); 678 uint16_t namelen = tox_getselfname(m, name, sizeof(name));
679
674 if (namelen > 0) { 680 if (namelen > 0) {
675 char whoami[128 + TOX_MAX_NAME_LENGTH]; 681 char whoami[128 + TOX_MAX_NAME_LENGTH];
676 snprintf(whoami, sizeof(whoami), "[i] your current username is: %s", name); 682 snprintf(whoami, sizeof(whoami), "[i] your current username is: %s", name);
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index f38ce3a5..84c00c70 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1579,6 +1579,7 @@ void DHT_save(DHT *dht, uint8_t *data)
1579 len = num * sizeof(Client_data); 1579 len = num * sizeof(Client_data);
1580 type = DHT_STATE_TYPE_CLIENTS; 1580 type = DHT_STATE_TYPE_CLIENTS;
1581 data = z_state_save_subheader(data, len, type); 1581 data = z_state_save_subheader(data, len, type);
1582
1582 if (num) { 1583 if (num) {
1583 Client_data *clients = (Client_data *)data; 1584 Client_data *clients = (Client_data *)data;
1584 1585
@@ -1586,6 +1587,7 @@ void DHT_save(DHT *dht, uint8_t *data)
1586 if (dht->close_clientlist[i].timestamp != 0) 1587 if (dht->close_clientlist[i].timestamp != 0)
1587 memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data)); 1588 memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data));
1588 } 1589 }
1590
1589 data += len; 1591 data += len;
1590} 1592}
1591 1593
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 0aacc703..d6bee5a1 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -788,7 +788,7 @@ int del_groupchat(Messenger *m, int groupnumber)
788 788
789/* Copy the name of peernumber who is in groupnumber to name. 789/* Copy the name of peernumber who is in groupnumber to name.
790 * name must be at least MAX_NICK_BYTES long. 790 * name must be at least MAX_NICK_BYTES long.
791 * 791 *
792 * return length of name if success 792 * return length of name if success
793 * return -1 if failure 793 * return -1 if failure
794 */ 794 */
@@ -802,6 +802,7 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam
802 802
803 if (m->chats[groupnumber] == NULL) 803 if (m->chats[groupnumber] == NULL)
804 return -1; 804 return -1;
805
805 return group_peername(m->chats[groupnumber], peernumber, name); 806 return group_peername(m->chats[groupnumber], peernumber, name);
806} 807}
807/* return 1 if that friend was invited to the group 808/* return 1 if that friend was invited to the group
@@ -1609,6 +1610,7 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
1609 break; 1610 break;
1610 1611
1611#ifdef DEBUG 1612#ifdef DEBUG
1613
1612 default: 1614 default:
1613 fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", 1615 fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n",
1614 length, type); 1616 length, type);
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 2aabd90d..78580dc0 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -403,7 +403,7 @@ int del_groupchat(Messenger *m, int groupnumber);
403 403
404/* Copy the name of peernumber who is in groupnumber to name. 404/* Copy the name of peernumber who is in groupnumber to name.
405 * name must be at least MAX_NICK_BYTES long. 405 * name must be at least MAX_NICK_BYTES long.
406 * 406 *
407 * return length of name if success 407 * return length of name if success
408 * return -1 if failure 408 * return -1 if failure
409 */ 409 */
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 23018cab..dc8e158b 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -281,7 +281,7 @@ static int delpeer(Group_Chat *chat, uint8_t *client_id)
281 281
282/* Copy the name of peernum to name. 282/* Copy the name of peernum to name.
283 * name must be at least MAX_NICK_BYTES long. 283 * name must be at least MAX_NICK_BYTES long.
284 * 284 *
285 * return length of name if success 285 * return length of name if success
286 * return -1 if failure 286 * return -1 if failure
287 */ 287 */
@@ -289,10 +289,12 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
289{ 289{
290 if ((uint32_t)peernum >= chat->numpeers) 290 if ((uint32_t)peernum >= chat->numpeers)
291 return -1; 291 return -1;
292
292 if (chat->group[peernum].nick_len == 0) { 293 if (chat->group[peernum].nick_len == 0) {
293 memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/ 294 memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/
294 return 10; 295 return 10;
295 } 296 }
297
296 memcpy(name, chat->group[peernum].nick, chat->group[peernum].nick_len); 298 memcpy(name, chat->group[peernum].nick, chat->group[peernum].nick_len);
297 return chat->group[peernum].nick_len; 299 return chat->group[peernum].nick_len;
298} 300}
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h
index 7089458c..e45f2af2 100644
--- a/toxcore/group_chats.h
+++ b/toxcore/group_chats.h
@@ -41,7 +41,7 @@ typedef struct {
41 uint64_t last_recv; 41 uint64_t last_recv;
42 uint64_t last_recv_msgping; 42 uint64_t last_recv_msgping;
43 uint32_t last_message_number; 43 uint32_t last_message_number;
44 44
45 uint8_t nick[MAX_NICK_BYTES]; 45 uint8_t nick[MAX_NICK_BYTES];
46 uint16_t nick_len; 46 uint16_t nick_len;
47} Group_Peer; 47} Group_Peer;
@@ -72,7 +72,7 @@ typedef struct Group_Chat {
72 72
73/* Copy the name of peernum to name. 73/* Copy the name of peernum to name.
74 * name must be at least MAX_NICK_BYTES long. 74 * name must be at least MAX_NICK_BYTES long.
75 * 75 *
76 * return length of name if success 76 * return length of name if success
77 * return -1 if failure 77 * return -1 if failure
78 */ 78 */
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 1de32cb0..a2e42557 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -456,7 +456,7 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
456 } 456 }
457 457
458 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1 458 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1
459 || c->crypto_connections == NULL) 459 || c->crypto_connections == NULL)
460 return -1; 460 return -1;
461 461
462 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); 462 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
@@ -580,7 +580,7 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
580 * } 580 * }
581 */ 581 */
582 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1 582 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1
583 || c->crypto_connections == NULL) 583 || c->crypto_connections == NULL)
584 return -1; 584 return -1;
585 585
586 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); 586 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 78074db1..4fba360b 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -410,7 +410,7 @@ int tox_del_groupchat(void *tox, int groupnumber)
410 410
411/* Copy the name of peernumber who is in groupnumber to name. 411/* Copy the name of peernumber who is in groupnumber to name.
412 * name must be at least MAX_NICK_BYTES long. 412 * name must be at least MAX_NICK_BYTES long.
413 * 413 *
414 * return length of name if success 414 * return length of name if success
415 * return -1 if failure 415 * return -1 if failure
416 */ 416 */
diff --git a/toxcore/tox.h b/toxcore/tox.h
index cc7fc5ec..b39008fe 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -378,7 +378,7 @@ int tox_del_groupchat(Tox *tox, int groupnumber);
378 378
379/* Copy the name of peernumber who is in groupnumber to name. 379/* Copy the name of peernumber who is in groupnumber to name.
380 * name must be at least TOX_MAX_NAME_LENGTH long. 380 * name must be at least TOX_MAX_NAME_LENGTH long.
381 * 381 *
382 * return length of name if success 382 * return length of name if success
383 * return -1 if failure 383 * return -1 if failure
384 */ 384 */
diff --git a/toxcore/util.h b/toxcore/util.h
index 6937f7d4..9e4ac79a 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -18,7 +18,7 @@ void id_cpy(uint8_t *dest, uint8_t *src);
18 18
19typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type); 19typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type);
20int load_state(load_state_callback_func load_state_callback, void *outer, 20int load_state(load_state_callback_func load_state_callback, void *outer,
21 uint8_t *data, uint32_t length, uint16_t cookie_inner); 21 uint8_t *data, uint32_t length, uint16_t cookie_inner);
22 22
23#undef LOGGING 23#undef LOGGING
24/* #define LOGGING */ 24/* #define LOGGING */