summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8291fab0..b13465ed 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -503,7 +503,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
503 return -3; 503 return -3;
504 } 504 }
505 505
506 uint8_t packet[length + 1]; 506 VLA(uint8_t, packet, length + 1);
507 packet[0] = type + PACKET_ID_MESSAGE; 507 packet[0] = type + PACKET_ID_MESSAGE;
508 508
509 if (length != 0) { 509 if (length != 0) {
@@ -965,7 +965,7 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_
965 return 0; 965 return 0;
966 } 966 }
967 967
968 uint8_t packet[length + 1]; 968 VLA(uint8_t, packet, length + 1);
969 packet[0] = packet_id; 969 packet[0] = packet_id;
970 970
971 if (length != 0) { 971 if (length != 0) {
@@ -1111,7 +1111,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
1111 return 0; 1111 return 0;
1112 } 1112 }
1113 1113
1114 uint8_t packet[1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH + filename_length]; 1114 VLA(uint8_t, packet, 1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH + filename_length);
1115 packet[0] = filenumber; 1115 packet[0] = filenumber;
1116 file_type = htonl(file_type); 1116 file_type = htonl(file_type);
1117 memcpy(packet + 1, &file_type, sizeof(file_type)); 1117 memcpy(packet + 1, &file_type, sizeof(file_type));
@@ -1123,7 +1123,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
1123 memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH, filename, filename_length); 1123 memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH, filename, filename_length);
1124 } 1124 }
1125 1125
1126 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, sizeof(packet), 0); 1126 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, SIZEOF_VLA(packet), 0);
1127} 1127}
1128 1128
1129/* Send a file send request. 1129/* Send a file send request.
@@ -1190,7 +1190,7 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui
1190 return -1; 1190 return -1;
1191 } 1191 }
1192 1192
1193 uint8_t packet[3 + data_length]; 1193 VLA(uint8_t, packet, 3 + data_length);
1194 1194
1195 packet[0] = send_receive; 1195 packet[0] = send_receive;
1196 packet[1] = filenumber; 1196 packet[1] = filenumber;
@@ -1200,7 +1200,7 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui
1200 memcpy(packet + 3, data, data_length); 1200 memcpy(packet + 3, data, data_length);
1201 } 1201 }
1202 1202
1203 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, sizeof(packet), 0); 1203 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, SIZEOF_VLA(packet), 0);
1204} 1204}
1205 1205
1206/* Send a file control request. 1206/* Send a file control request.
@@ -1378,7 +1378,7 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u
1378 return -1; 1378 return -1;
1379 } 1379 }
1380 1380
1381 uint8_t packet[2 + length]; 1381 VLA(uint8_t, packet, 2 + length);
1382 packet[0] = PACKET_ID_FILE_DATA; 1382 packet[0] = PACKET_ID_FILE_DATA;
1383 packet[1] = filenumber; 1383 packet[1] = filenumber;
1384 1384
@@ -1387,7 +1387,7 @@ static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, u
1387 } 1387 }
1388 1388
1389 return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, 1389 return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
1390 m->friendlist[friendnumber].friendcon_id), packet, sizeof(packet), 1); 1390 m->friendlist[friendnumber].friendcon_id), packet, SIZEOF_VLA(packet), 1);
1391} 1391}
1392 1392
1393#define MAX_FILE_DATA_SIZE (MAX_CRYPTO_DATA_SIZE - 2) 1393#define MAX_FILE_DATA_SIZE (MAX_CRYPTO_DATA_SIZE - 2)
@@ -2132,7 +2132,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2132 } 2132 }
2133 2133
2134 /* Make sure the NULL terminator is present. */ 2134 /* Make sure the NULL terminator is present. */
2135 uint8_t data_terminated[data_length + 1]; 2135 VLA(uint8_t, data_terminated, data_length + 1);
2136 memcpy(data_terminated, data, data_length); 2136 memcpy(data_terminated, data, data_length);
2137 data_terminated[data_length] = 0; 2137 data_terminated[data_length] = 0;
2138 2138
@@ -2153,7 +2153,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2153 } 2153 }
2154 2154
2155 /* Make sure the NULL terminator is present. */ 2155 /* Make sure the NULL terminator is present. */
2156 uint8_t data_terminated[data_length + 1]; 2156 VLA(uint8_t, data_terminated, data_length + 1);
2157 memcpy(data_terminated, data, data_length); 2157 memcpy(data_terminated, data, data_length);
2158 data_terminated[data_length] = 0; 2158 data_terminated[data_length] = 0;
2159 2159
@@ -2210,7 +2210,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2210 uint16_t message_length = data_length; 2210 uint16_t message_length = data_length;
2211 2211
2212 /* Make sure the NULL terminator is present. */ 2212 /* Make sure the NULL terminator is present. */
2213 uint8_t message_terminated[message_length + 1]; 2213 VLA(uint8_t, message_terminated, message_length + 1);
2214 memcpy(message_terminated, message, message_length); 2214 memcpy(message_terminated, message, message_length);
2215 message_terminated[message_length] = 0; 2215 message_terminated[message_length] = 0;
2216 uint8_t type = packet_id - PACKET_ID_MESSAGE; 2216 uint8_t type = packet_id - PACKET_ID_MESSAGE;
@@ -2272,7 +2272,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2272 ft->paused = FILE_PAUSE_NOT; 2272 ft->paused = FILE_PAUSE_NOT;
2273 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH); 2273 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
2274 2274
2275 uint8_t filename_terminated[filename_length + 1]; 2275 VLA(uint8_t, filename_terminated, filename_length + 1);
2276 uint8_t *filename = NULL; 2276 uint8_t *filename = NULL;
2277 2277
2278 if (filename_length) { 2278 if (filename_length) {
@@ -2584,8 +2584,8 @@ void do_messenger(Messenger *m, void *userdata)
2584 2584
2585 /* dht contains additional "friends" (requests) */ 2585 /* dht contains additional "friends" (requests) */
2586 uint32_t num_dhtfriends = m->dht->num_friends; 2586 uint32_t num_dhtfriends = m->dht->num_friends;
2587 int32_t m2dht[num_dhtfriends]; 2587 VLA(int32_t, m2dht, num_dhtfriends);
2588 int32_t dht2m[num_dhtfriends]; 2588 VLA(int32_t, dht2m, num_dhtfriends);
2589 2589
2590 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) { 2590 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
2591 m2dht[friend_idx] = -1; 2591 m2dht[friend_idx] = -1;