[FFmpeg-devel] [PATCH] fix check in dyn_buf_write that gcc 4.3 optimizes away

Reimar Döffinger Reimar.Doeffinger
Sat Oct 4 18:17:09 CEST 2008


Hello,
newest gcc when optimizing comparisons assumes that no overflows happen,
breaking this way of checking.
Attached patch fixes it - I hope it to be uncontroversial since we
already avoided relying on this kind of check in several other
places.

Greetings,
Reimar D?ffinger
-------------- next part --------------
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 34029a5..5e518bf 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -716,7 +716,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
     /* reallocate buffer if needed */
     new_size = d->pos + buf_size;
     new_allocated_size = d->allocated_size;
-    if(new_size < d->pos || new_size > INT_MAX/2)
+    if(buf_size > INT_MAX - d->pos || new_size > INT_MAX/2)
         return -1;
     while (new_size > new_allocated_size) {
         if (!new_allocated_size)



More information about the ffmpeg-devel mailing list