diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-05-24 04:02:27 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-06-11 02:01:56 +0200 |
commit | 88d5ae068fa5a7047665a2b680882725f8011e56 (patch) | |
tree | 1b0425a3ee92b4c0920e2017224a8ea4e3014d94 /libavformat/aviobuf.c | |
parent | 28a078eded1c29985ed078b59d48ff59cf00394b (diff) |
avformat/aviobuf: Simplify dyn_buf_write() a bit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 0e6125e161..12408fd211 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1284,22 +1284,19 @@ typedef struct DynBuffer { static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) { DynBuffer *d = opaque; - unsigned new_size, new_allocated_size; + unsigned new_size; /* reallocate buffer if needed */ new_size = (unsigned)d->pos + buf_size; - new_allocated_size = d->allocated_size; if (new_size < d->pos || new_size > INT_MAX/2) return -1; - while (new_size > new_allocated_size) { - if (!new_allocated_size) - new_allocated_size = new_size; - else + if (new_size > d->allocated_size) { + unsigned new_allocated_size = d->allocated_size ? d->allocated_size + : new_size; + int err; + while (new_size > new_allocated_size) new_allocated_size += new_allocated_size / 2 + 1; - } - if (new_allocated_size > d->allocated_size) { - int err; if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) { d->allocated_size = 0; d->size = 0; |