aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/oggdec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2020-05-01 14:33:46 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2020-05-01 23:30:35 +0200
commit5d5b0bbcb7d1d71a19dcec9b71fe59a4deea2fcd (patch)
tree3ba65dd9ccd57fac2517e39af40fa0092e74009a /libavformat/oggdec.c
parent3c740f2d9f573542313ea64d7ab45fd1669ee511 (diff)
downloadffmpeg-5d5b0bbcb7d1d71a19dcec9b71fe59a4deea2fcd.tar.gz
avformat/oggdec: Factor buffer reallocation out
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/oggdec.c')
-rw-r--r--libavformat/oggdec.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index c591bafddd..a9034ea61c 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -297,6 +297,20 @@ static int data_packets_seen(const struct ogg *ogg)
return 0;
}
+static int buf_realloc(struct ogg_stream *os, int size)
+{
+ /* Even if invalid guarantee there's enough memory to read the page */
+ if (os->bufsize - os->bufpos < size) {
+ uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!nb)
+ return AVERROR(ENOMEM);
+ os->buf = nb;
+ os->bufsize *= 2;
+ }
+
+ return 0;
+}
+
static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
{
AVIOContext *bc = s->pb;
@@ -378,14 +392,9 @@ static int ogg_read_page(AVFormatContext *s, int *sid, int probing)
if (idx >= 0) {
os = ogg->streams + idx;
- /* Even if invalid guarantee there's enough memory to read the page */
- if (os->bufsize - os->bufpos < size) {
- uint8_t *nb = av_realloc(os->buf, 2*os->bufsize + AV_INPUT_BUFFER_PADDING_SIZE);
- if (!nb)
- return AVERROR(ENOMEM);
- os->buf = nb;
- os->bufsize *= 2;
- }
+ ret = buf_realloc(os, size);
+ if (ret < 0)
+ return ret;
readout_buf = os->buf + os->bufpos;
} else {