[FFmpeg-cvslog] qt-faststart: dont allocate a bigger buffer than needed

Michael Niedermayer git at videolan.org
Sun Sep 30 22:21:10 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Sep 30 21:52:59 2012 +0200| [610efb67739f850d7d08779f55661e15bc6f6722] | committer: Michael Niedermayer

qt-faststart: dont allocate a bigger buffer than needed

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=610efb67739f850d7d08779f55661e15bc6f6722
---

 tools/qt-faststart.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index bfa6f1a..b1917f1 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -37,6 +37,8 @@
 #define ftello(x)       _ftelli64(x)
 #endif
 
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+
 #define BE_16(x) ((((uint8_t*)(x))[0] <<  8) | ((uint8_t*)(x))[1])
 
 #define BE_32(x) ((((uint8_t*)(x))[0] << 24) |  \
@@ -293,9 +295,10 @@ int main(int argc, char *argv[])
     }
 
     /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
-    copy_buffer = malloc(COPY_BUFFER_SIZE);
+    bytes_to_copy = FFMIN(COPY_BUFFER_SIZE, last_offset);
+    copy_buffer = malloc(bytes_to_copy);
     if (!copy_buffer) {
-        printf("could not allocate %"PRIu64" bytes for copy_buffer\n", COPY_BUFFER_SIZE);
+        printf("could not allocate %"PRIu64" bytes for copy_buffer\n", bytes_to_copy);
         goto error_out;
     }
     printf(" copying rest of file...\n");



More information about the ffmpeg-cvslog mailing list