diff options
author | Max Kellermann <max@duempel.org> | 2009-02-09 16:36:11 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-09 16:38:25 +0100 |
commit | 1ac328b553df550c25bd0000e190d4cdd7c54a08 (patch) | |
tree | f18f9adf6240005f4536888311132340256751aa /src/output/shout_ogg.c | |
parent | 7fc25ad567a0b8b4f7c05832adc17e9fdcc2cefb (diff) | |
download | mpd-1ac328b553df550c25bd0000e190d4cdd7c54a08.tar.gz mpd-1ac328b553df550c25bd0000e190d4cdd7c54a08.tar.xz mpd-1ac328b553df550c25bd0000e190d4cdd7c54a08.zip |
shout: clear buffer before calling the encoder
Always assume the buffer is empty before calling the encoder. Always
flush the buffer immediately after there has been added something.
This reduces the risk of buffer overruns, because there will never be
a "rest" in the current buffer.
Diffstat (limited to 'src/output/shout_ogg.c')
-rw-r--r-- | src/output/shout_ogg.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/output/shout_ogg.c b/src/output/shout_ogg.c index d5766d0a3..ebf84c0bf 100644 --- a/src/output/shout_ogg.c +++ b/src/output/shout_ogg.c @@ -75,23 +75,14 @@ static void copy_tag_to_vorbis_comment(struct shout_data *sd) static int copy_ogg_buffer_to_shout_buffer(ogg_page *og, struct shout_buffer *buf) { - if (sizeof(buf->data) - buf->len >= (size_t)og->header_len) { - memcpy(buf->data + buf->len, - og->header, og->header_len); - buf->len += og->header_len; - } else { + if ((size_t)og->header_len + (size_t)og->body_len > sizeof(buf->data)) { g_warning("%s: not enough buffer space!\n", __func__); return -1; } - if (sizeof(buf->data) - buf->len >= (size_t)og->body_len) { - memcpy(buf->data + buf->len, - og->body, og->body_len); - buf->len += og->body_len; - } else { - g_warning("%s: not enough buffer space!\n", __func__); - return -1; - } + memcpy(buf->data, og->header, og->header_len); + memcpy(buf->data + og->header_len, og->body, og->body_len); + buf->len = og->header_len + og->body_len; return 0; } |