diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2015-07-11 23:08:08 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-07-11 23:24:16 +0200 |
commit | 59a07df0673122b334af1f26367f6a49a0ec121b (patch) | |
tree | 7c413f6ab1828b903dede42aa895705251a65858 | |
parent | b3415e4c5f9205820fd6c9211ad50a4df2692a36 (diff) | |
download | ffmpeg-streaming-59a07df0673122b334af1f26367f6a49a0ec121b.zip ffmpeg-streaming-59a07df0673122b334af1f26367f6a49a0ec121b.tar.gz |
avcodec/utils: Avoid undefined void casts in ff_fast_malloc()
based on code from libavutil/mem.c
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavcodec/utils.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 0910fca..b086665 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -124,13 +124,16 @@ static void *avformat_mutex; static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) { - void **p = ptr; - if (min_size <= *size && *p) + void *val; + + memcpy(&val, ptr, sizeof(val)); + if (min_size <= *size && val) return 0; min_size = FFMAX(min_size + min_size / 16 + 32, min_size); - av_free(*p); - *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); - if (!*p) + av_freep(ptr); + val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); + memcpy(ptr, &val, sizeof(val)); + if (!val) min_size = 0; *size = min_size; return 1; |