[FFmpeg-devel] [PATCH 1/4] lavu/opt: make sure av_opt_set_bin() handles NULL/0.

Nicolas George nicolas.george at normalesup.org
Thu Mar 28 17:18:25 CET 2013


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavutil/opt.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 97fc6fd..8817a1d 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -420,8 +420,8 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
     if (o->type != AV_OPT_TYPE_BINARY)
         return AVERROR(EINVAL);
 
-    ptr = av_malloc(len);
-    if (!ptr)
+    ptr = len ? av_malloc(len) : NULL;
+    if (len && !ptr)
         return AVERROR(ENOMEM);
 
     dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
@@ -430,7 +430,8 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
     av_free(*dst);
     *dst = ptr;
     *lendst = len;
-    memcpy(ptr, val, len);
+    if (len)
+        memcpy(ptr, val, len);
 
     return 0;
 }
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list