diff options
author | iphydf <iphydf@users.noreply.github.com> | 2017-01-20 21:16:55 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2017-01-28 20:49:12 +0000 |
commit | 6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch) | |
tree | 99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /testing | |
parent | 895de7ef26e7617769f2271345e414545c2581f8 (diff) |
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/irc_syncbot.c | 7 | ||||
-rw-r--r-- | testing/nTox.c | 24 | ||||
-rw-r--r-- | testing/tox_sync.c | 5 |
3 files changed, 20 insertions, 16 deletions
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index 783be51a..91267f84 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c | |||
@@ -83,6 +83,7 @@ static int reconnect(void) | |||
83 | return new_sock; | 83 | return new_sock; |
84 | } | 84 | } |
85 | 85 | ||
86 | #include "../toxcore/ccompat.h" | ||
86 | #include "../toxcore/tox.h" | 87 | #include "../toxcore/tox.h" |
87 | #include "misc_tools.c" | 88 | #include "misc_tools.c" |
88 | 89 | ||
@@ -178,7 +179,7 @@ static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | |||
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | 181 | ||
181 | uint8_t req[len]; | 182 | VLA(uint8_t, req, len); |
182 | unsigned int i; | 183 | unsigned int i; |
183 | 184 | ||
184 | unsigned int spaces = 0; | 185 | unsigned int spaces = 0; |
@@ -198,7 +199,7 @@ static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | |||
198 | unsigned int req_len = i; | 199 | unsigned int req_len = i; |
199 | req[i] = 0; | 200 | req[i] = 0; |
200 | 201 | ||
201 | uint8_t message[len]; | 202 | VLA(uint8_t, message, len); |
202 | uint16_t length = 0; | 203 | uint16_t length = 0; |
203 | 204 | ||
204 | uint8_t *pmsg = (uint8_t *)strstr((char *)req, " PRIVMSG"); | 205 | uint8_t *pmsg = (uint8_t *)strstr((char *)req, " PRIVMSG"); |
@@ -298,7 +299,7 @@ int main(int argc, char *argv[]) | |||
298 | if (count > 0) { | 299 | if (count > 0) { |
299 | last_get = get_monotime_sec(); | 300 | last_get = get_monotime_sec(); |
300 | ping_sent = 0; | 301 | ping_sent = 0; |
301 | uint8_t data[count + 1]; | 302 | VLA(uint8_t, data, count + 1); |
302 | data[count] = 0; | 303 | data[count] = 0; |
303 | recv(sock, data, count, MSG_NOSIGNAL); | 304 | recv(sock, data, count, MSG_NOSIGNAL); |
304 | printf("%s", data); | 305 | printf("%s", data); |
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); |
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index c719b3ec..d2fc41ca 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "config.h" | 34 | #include "config.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include "../toxcore/ccompat.h" | ||
37 | #include "../toxcore/tox.h" | 38 | #include "../toxcore/tox.h" |
38 | #include "misc_tools.c" | 39 | #include "misc_tools.c" |
39 | 40 | ||
@@ -73,7 +74,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi | |||
73 | } | 74 | } |
74 | 75 | ||
75 | fseek(file_senders[i].file, position, SEEK_SET); | 76 | fseek(file_senders[i].file, position, SEEK_SET); |
76 | uint8_t data[length]; | 77 | VLA(uint8_t, data, length); |
77 | int len = fread(data, 1, length, file_senders[i].file); | 78 | int len = fread(data, 1, length, file_senders[i].file); |
78 | tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0); | 79 | tox_file_send_chunk(tox, friend_number, file_number, position, data, len, 0); |
79 | break; | 80 | break; |
@@ -314,7 +315,7 @@ int main(int argc, char *argv[]) | |||
314 | 315 | ||
315 | if (d) { | 316 | if (d) { |
316 | while ((dir = readdir(d)) != NULL) { | 317 | while ((dir = readdir(d)) != NULL) { |
317 | char filepath[strlen(path) + strlen(dir->d_name) + 1]; | 318 | VLA(char, filepath, strlen(path) + strlen(dir->d_name) + 1); |
318 | memcpy(filepath, path, strlen(path)); | 319 | memcpy(filepath, path, strlen(path)); |
319 | memcpy(filepath + strlen(path), dir->d_name, strlen(dir->d_name) + 1); | 320 | memcpy(filepath + strlen(path), dir->d_name, strlen(dir->d_name) + 1); |
320 | stat(filepath, &statbuf); | 321 | stat(filepath, &statbuf); |