summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 160aef29..d02a1652 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -39,6 +39,7 @@
39 39
40#include <sys/select.h> 40#include <sys/select.h>
41 41
42#include "../toxcore/ccompat.h"
42#include "misc_tools.c" 43#include "misc_tools.c"
43#include "nTox.h" 44#include "nTox.h"
44 45
@@ -144,7 +145,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
144 } 145 }
145 146
146 fseek(file_senders[i].file, position, SEEK_SET); 147 fseek(file_senders[i].file, position, SEEK_SET);
147 uint8_t data[length]; 148 VLA(uint8_t, data, length);
148 int len = fread(data, 1, length, file_senders[i].file); 149 int len = fread(data, 1, length, file_senders[i].file);
149 tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0); 150 tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0);
150 break; 151 break;
@@ -266,7 +267,7 @@ static void print_friendlist(Tox *m)
266 char fraddr_str[FRADDR_TOSTR_BUFSIZE]; 267 char fraddr_str[FRADDR_TOSTR_BUFSIZE];
267 268
268 /* account for the longest name and the longest "base" string and number (int) and id_str */ 269 /* account for the longest name and the longest "base" string and number (int) and id_str */
269 char fstring[TOX_MAX_NAME_LENGTH + strlen(ptrn_friend) + 21 + id_str_len]; 270 VLA(char, fstring, TOX_MAX_NAME_LENGTH + strlen(ptrn_friend) + 21 + id_str_len);
270 271
271 uint32_t i = 0; 272 uint32_t i = 0;
272 273
@@ -299,7 +300,7 @@ static void print_formatted_message(Tox *m, char *message, int friendnum, uint8_
299 char name[TOX_MAX_NAME_LENGTH + 1]; 300 char name[TOX_MAX_NAME_LENGTH + 1];
300 getfriendname_terminated(m, friendnum, name); 301 getfriendname_terminated(m, friendnum, name);
301 302
302 char msg[100 + strlen(message) + strlen(name) + 1]; 303 VLA(char, msg, 100 + strlen(message) + strlen(name) + 1);
303 304
304 time_t rawtime; 305 time_t rawtime;
305 struct tm *timeinfo; 306 struct tm *timeinfo;
@@ -920,7 +921,7 @@ static void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type,
920 void *userdata) 921 void *userdata)
921{ 922{
922 /* ensure null termination */ 923 /* ensure null termination */
923 uint8_t null_string[length + 1]; 924 VLA(uint8_t, null_string, length + 1);
924 memcpy(null_string, string, length); 925 memcpy(null_string, string, length);
925 null_string[length] = 0; 926 null_string[length] = 0;
926 print_formatted_message(m, (char *)null_string, friendnumber, 0); 927 print_formatted_message(m, (char *)null_string, friendnumber, 0);
@@ -931,7 +932,7 @@ static void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *strin
931 char name[TOX_MAX_NAME_LENGTH + 1]; 932 char name[TOX_MAX_NAME_LENGTH + 1];
932 933
933 if (getfriendname_terminated(m, friendnumber, name) != -1) { 934 if (getfriendname_terminated(m, friendnumber, name) != -1) {
934 char msg[100 + length]; 935 VLA(char, msg, 100 + length);
935 936
936 if (name[0] != 0) { 937 if (name[0] != 0) {
937 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); 938 sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string);
@@ -948,7 +949,7 @@ static void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *str
948 char name[TOX_MAX_NAME_LENGTH + 1]; 949 char name[TOX_MAX_NAME_LENGTH + 1];
949 950
950 if (getfriendname_terminated(m, friendnumber, name) != -1) { 951 if (getfriendname_terminated(m, friendnumber, name) != -1) {
951 char msg[100 + length + strlen(name) + 1]; 952 VLA(char, msg, 100 + length + strlen(name) + 1);
952 953
953 if (name[0] != 0) { 954 if (name[0] != 0) {
954 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); 955 sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string);
@@ -971,7 +972,7 @@ static Tox *load_data(void)
971 size_t size = ftell(data_file); 972 size_t size = ftell(data_file);
972 rewind(data_file); 973 rewind(data_file);
973 974
974 uint8_t data[size]; 975 VLA(uint8_t, data, size);
975 976
976 if (fread(data, sizeof(uint8_t), size, data_file) != size) { 977 if (fread(data, sizeof(uint8_t), size, data_file) != size) {
977 fputs("[!] could not read data file!\n", stderr); 978 fputs("[!] could not read data file!\n", stderr);
@@ -1014,7 +1015,7 @@ static int save_data(Tox *m)
1014 1015
1015 int res = 1; 1016 int res = 1;
1016 size_t size = tox_get_savedata_size(m); 1017 size_t size = tox_get_savedata_size(m);
1017 uint8_t data[size]; 1018 VLA(uint8_t, data, size);
1018 tox_get_savedata(m, data); 1019 tox_get_savedata(m, data);
1019 1020
1020 if (fwrite(data, sizeof(uint8_t), size, data_file) != size) { 1021 if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
@@ -1080,8 +1081,9 @@ static void print_groupchatpeers(Tox *m, int groupnumber)
1080 return; 1081 return;
1081 } 1082 }
1082 1083
1083 uint8_t names[num][TOX_MAX_NAME_LENGTH]; 1084 typedef uint8_t Peer_Name[TOX_MAX_NAME_LENGTH];
1084 size_t lengths[num]; 1085 VLA(Peer_Name, names, num);
1086 VLA(size_t, lengths, num);
1085 1087
1086 uint32_t i; 1088 uint32_t i;
1087 1089
@@ -1126,7 +1128,7 @@ static void print_groupmessage(Tox *m, uint32_t groupnumber, uint32_t peernumber
1126 const uint8_t *message, size_t length, 1128 const uint8_t *message, size_t length,
1127 void *userdata) 1129 void *userdata)
1128{ 1130{
1129 char msg[256 + length]; 1131 VLA(char, msg, 256 + length);
1130 1132
1131 TOX_ERR_CONFERENCE_PEER_QUERY error; 1133 TOX_ERR_CONFERENCE_PEER_QUERY error;
1132 size_t len = tox_conference_peer_get_name_size(m, groupnumber, peernumber, &error); 1134 size_t len = tox_conference_peer_get_name_size(m, groupnumber, peernumber, &error);