From 6ae33c16cf9e37fda85d70c78b3c2779eb8ca21a Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 20 Jan 2017 21:16:55 +0000 Subject: Add VLA compatibility macro for C89-ish compilers. --- toxav/groupav.c | 4 ++-- toxav/rtp.c | 10 +++++----- toxav/toxav.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'toxav') 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, } Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); - uint8_t data[1 + sizeof(uint16_t) + length]; + VLA(uint8_t, data, 1 + sizeof(uint16_t) + length); data[0] = GROUP_AUDIO_PACKET_ID; uint16_t sequnum = htons(group_av->audio_sequnum); memcpy(data + 1, &sequnum, sizeof(sequnum)); memcpy(data + 1 + sizeof(sequnum), packet, length); - if (send_group_lossy_packet(g_c, groupnumber, data, sizeof(data)) == -1) { + if (send_group_lossy_packet(g_c, groupnumber, data, SIZEOF_VLA(data)) == -1) { return -1; } 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 return -1; } - uint8_t rdata[length + sizeof(struct RTPHeader) + 1]; - memset(rdata, 0, sizeof(rdata)); + VLA(uint8_t, rdata, length + sizeof(struct RTPHeader) + 1); + memset(rdata, 0, SIZEOF_VLA(rdata)); rdata[0] = session->payload_type; - struct RTPHeader *header = (struct RTPHeader *)(rdata + 1); + struct RTPHeader *header = (struct RTPHeader *)(rdata + 1); header->ve = 2; header->pe = 0; @@ -147,8 +147,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log memcpy(rdata + 1 + sizeof(struct RTPHeader), data, length); - if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, sizeof(rdata))) { - LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", sizeof(rdata), strerror(errno)); + if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) { + LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", SIZEOF_VLA(rdata), strerror(errno)); } } else { 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 goto END; } - uint8_t dest[sample_count + sizeof(sampling_rate)]; /* This is more than enough always */ + VLA(uint8_t, dest, sample_count + sizeof(sampling_rate)); /* This is more than enough always */ sampling_rate = htonl(sampling_rate); memcpy(dest, &sampling_rate, sizeof(sampling_rate)); int vrc = opus_encode(call->audio.second->encoder, pcm, sample_count, - dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate)); + dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate)); if (vrc < 0) { LOGGER_WARNING(av->m->log, "Failed to encode frame %s", opus_strerror(vrc)); -- cgit v1.2.3