diff mbox series

[FFmpeg-devel,2/5] avformat/aviobuf: Simplify dyn_buf_write() a bit

Message ID 20200525140801.18889-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 88d5ae068fa5a7047665a2b680882725f8011e56
Headers show
Series [FFmpeg-devel,1/5] avformat/aviobuf: Don't check for overflow after it happened
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 25, 2020, 2:07 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/aviobuf.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 33c2d6f037..fcde7e8510 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1272,22 +1272,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;