Commit 59a07df0 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/utils: Avoid undefined void casts in ff_fast_malloc()

based on code from libavutil/mem.c
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent b3415e4c
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment