summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c10
1 files changed, 8 insertions, 2 deletions
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);