From: Nicolas George Date: Thu, 28 Mar 2013 15:45:12 +0000 (+0100) Subject: lavu/opt: make sure av_opt_set_bin() handles NULL/0. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;ds=sidebyside;h=983d04dd40a40d2d099d9c382e84da49fd2fe031;p=ffmpeg lavu/opt: make sure av_opt_set_bin() handles NULL/0. --- diff --git a/libavutil/opt.c b/libavutil/opt.c index fb3b724bd65..ab73913a390 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; }