summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-20 21:16:55 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-01-28 20:49:12 +0000
commit6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a (patch)
tree99c3a8c26e02039b515bb6f57d2797d1cdf77c1d /toxav
parent895de7ef26e7617769f2271345e414545c2581f8 (diff)
Add VLA compatibility macro for C89-ish compilers.
Diffstat (limited to 'toxav')
-rw-r--r--toxav/groupav.c4
-rw-r--r--toxav/rtp.c10
-rw-r--r--toxav/toxav.c4
3 files changed, 9 insertions, 9 deletions
diff --git a/toxav/groupav.c b/toxav/groupav.c
index 6d84b480..2e77ec53 100644
--- a/toxav/groupav.c
+++ b/toxav/groupav.c
@@ -510,14 +510,14 @@ static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet,
510 } 510 }
511 511
512 Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); 512 Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber);
513 uint8_t data[1 + sizeof(uint16_t) + length]; 513 VLA(uint8_t, data, 1 + sizeof(uint16_t) + length);
514 data[0] = GROUP_AUDIO_PACKET_ID; 514 data[0] = GROUP_AUDIO_PACKET_ID;
515 515
516 uint16_t sequnum = htons(group_av->audio_sequnum); 516 uint16_t sequnum = htons(group_av->audio_sequnum);
517 memcpy(data + 1, &sequnum, sizeof(sequnum)); 517 memcpy(data + 1, &sequnum, sizeof(sequnum));
518 memcpy(data + 1 + sizeof(sequnum), packet, length); 518 memcpy(data + 1 + sizeof(sequnum), packet, length);
519 519
520 if (send_group_lossy_packet(g_c, groupnumber, data, sizeof(data)) == -1) { 520 if (send_group_lossy_packet(g_c, groupnumber, data, SIZEOF_VLA(data)) == -1) {
521 return -1; 521 return -1;
522 } 522 }
523 523
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 9b7b1bfe..9403a43d 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -116,12 +116,12 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log
116 return -1; 116 return -1;
117 } 117 }
118 118
119 uint8_t rdata[length + sizeof(struct RTPHeader) + 1]; 119 VLA(uint8_t, rdata, length + sizeof(struct RTPHeader) + 1);
120 memset(rdata, 0, sizeof(rdata)); 120 memset(rdata, 0, SIZEOF_VLA(rdata));
121 121
122 rdata[0] = session->payload_type; 122 rdata[0] = session->payload_type;
123 123
124 struct RTPHeader *header = (struct RTPHeader *)(rdata + 1); 124 struct RTPHeader *header = (struct RTPHeader *)(rdata + 1);
125 125
126 header->ve = 2; 126 header->ve = 2;
127 header->pe = 0; 127 header->pe = 0;
@@ -147,8 +147,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log
147 147
148 memcpy(rdata + 1 + sizeof(struct RTPHeader), data, length); 148 memcpy(rdata + 1 + sizeof(struct RTPHeader), data, length);
149 149
150 if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, sizeof(rdata))) { 150 if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) {
151 LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", sizeof(rdata), strerror(errno)); 151 LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", SIZEOF_VLA(rdata), strerror(errno));
152 } 152 }
153 } else { 153 } else {
154 154
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 1710f2a4..58db4597 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -704,12 +704,12 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
704 goto END; 704 goto END;
705 } 705 }
706 706
707 uint8_t dest[sample_count + sizeof(sampling_rate)]; /* This is more than enough always */ 707 VLA(uint8_t, dest, sample_count + sizeof(sampling_rate)); /* This is more than enough always */
708 708
709 sampling_rate = htonl(sampling_rate); 709 sampling_rate = htonl(sampling_rate);
710 memcpy(dest, &sampling_rate, sizeof(sampling_rate)); 710 memcpy(dest, &sampling_rate, sizeof(sampling_rate));
711 int vrc = opus_encode(call->audio.second->encoder, pcm, sample_count, 711 int vrc = opus_encode(call->audio.second->encoder, pcm, sample_count,
712 dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate)); 712 dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate));
713 713
714 if (vrc < 0) { 714 if (vrc < 0) {
715 LOGGER_WARNING(av->m->log, "Failed to encode frame %s", opus_strerror(vrc)); 715 LOGGER_WARNING(av->m->log, "Failed to encode frame %s", opus_strerror(vrc));