[FFmpeg-cvslog] tools/ffeval: use av_dynarray2_add()

Stefano Sabatini git at videolan.org
Mon May 13 14:27:23 CEST 2013


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sat Apr 27 22:46:49 2013 +0200| [3a4c8788e3239e5ff89ed0aea7f4936bd6e62032] | committer: Stefano Sabatini

tools/ffeval: use av_dynarray2_add()

Simplify, increment robustness.

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

 tools/ffeval.c |   32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/tools/ffeval.c b/tools/ffeval.c
index 0fab877..4f60688 100644
--- a/tools/ffeval.c
+++ b/tools/ffeval.c
@@ -24,6 +24,7 @@
 #endif
 
 #include "libavutil/eval.h"
+#include "libavutil/mem.h"
 
 #if !HAVE_GETOPT
 #include "compat/getopt.c"
@@ -47,20 +48,26 @@ static void usage(void)
            "-p PROMPT         set output prompt\n");
 }
 
-#define MAX_BLOCK_SIZE SIZE_MAX
-
 int main(int argc, char **argv)
 {
-    size_t buf_size = 256;
-    char *buf = av_malloc(buf_size);
+    int buf_size = 0;
+    char *buf = NULL;
     const char *outfilename = NULL, *infilename = NULL;
     FILE *outfile = NULL, *infile = NULL;
     const char *prompt = "=> ";
     int count = 0, echo = 0;
     int c;
 
-    av_max_alloc(MAX_BLOCK_SIZE);
+#define GROW_ARRAY()                                                    \
+    do {                                                                \
+        if (!av_dynarray2_add((void **)&buf, &buf_size, 1, NULL)) {     \
+            av_log(NULL, AV_LOG_ERROR,                                  \
+                   "Memory allocation problem occurred\n");             \
+            return 1;                                                   \
+        }                                                               \
+    } while (0)
 
+    GROW_ARRAY();
     while ((c = getopt(argc, argv, "ehi:o:p:")) != -1) {
         switch (c) {
         case 'e':
@@ -120,19 +127,8 @@ int main(int argc, char **argv)
             }
             count = 0;
         } else {
-            if (count >= buf_size-1) {
-                if (buf_size == MAX_BLOCK_SIZE) {
-                    av_log(NULL, AV_LOG_ERROR, "Memory allocation problem, "
-                           "max block size '%zd' reached\n", MAX_BLOCK_SIZE);
-                    return 1;
-                }
-                buf_size = FFMIN(buf_size, MAX_BLOCK_SIZE / 2) * 2;
-                buf = av_realloc_f((void *)buf, buf_size, 1);
-                if (!buf) {
-                    av_log(NULL, AV_LOG_ERROR, "Memory allocation problem occurred\n");
-                    return 1;
-                }
-            }
+            if (count >= buf_size-1)
+                GROW_ARRAY();
             buf[count++] = c;
         }
     }



More information about the ffmpeg-cvslog mailing list