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

Reimar Döffinger Reimar.Doeffinger
Sat Oct 4 23:28:08 CEST 2008


On Sat, Oct 04, 2008 at 10:52:59PM +0200, Michael Niedermayer wrote:
> On Sat, Oct 04, 2008 at 10:02:35PM +0200, Reimar D?ffinger wrote:
> >  Btw. with function also has a weird "return -1234;" that
> > looks a lot like nonsense to me...
> 
> well, it looks like nonsense to me too :)

Maybe someone can clean the whole file up a bit?
Attached patch touches some places I found particularly weird/ugly,
I did not even test compilation though.

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/aviobuf.c
===================================================================
--- libavformat/aviobuf.c	(revision 15555)
+++ libavformat/aviobuf.c	(working copy)
@@ -728,7 +728,7 @@
     if (new_allocated_size > d->allocated_size) {
         d->buffer = av_realloc(d->buffer, new_allocated_size);
         if(d->buffer == NULL)
-             return -1234;
+             return AVERROR(ENOMEM);
         d->allocated_size = new_allocated_size;
     }
     memcpy(d->buffer + d->pos, buf, buf_size);
@@ -744,10 +744,7 @@
     int ret;
 
     /* packetized write: output the header */
-    buf1[0] = (buf_size >> 24);
-    buf1[1] = (buf_size >> 16);
-    buf1[2] = (buf_size >> 8);
-    buf1[3] = (buf_size);
+    AV_WB32(buf1, buf_size);
     ret= dyn_buf_write(opaque, buf1, 4);
     if(ret < 0)
         return ret;
@@ -773,28 +770,20 @@
 static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size)
 {
     DynBuffer *d;
-    int io_buffer_size, ret;
+    int ret;
+    unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
 
-    if (max_packet_size)
-        io_buffer_size = max_packet_size;
-    else
-        io_buffer_size = 1024;
-
     if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
         return -1;
-    d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
+    d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
     if (!d)
-        return -1;
+        return AVERROR(ENOMEM);
     *s = av_mallocz(sizeof(ByteIOContext));
     if(!*s) {
         av_free(d);
         return AVERROR(ENOMEM);
     }
     d->io_buffer_size = io_buffer_size;
-    d->buffer = NULL;
-    d->pos = 0;
-    d->size = 0;
-    d->allocated_size = 0;
     ret = init_put_byte(*s, d->io_buffer, io_buffer_size,
                         1, d, NULL,
                         max_packet_size ? dyn_packet_buf_write : dyn_buf_write,



More information about the ffmpeg-devel mailing list