[FFmpeg-cvslog] avcodec/utils: Avoid undefined void casts in ff_fast_malloc()

Michael Niedermayer git at videolan.org
Sat Jul 11 23:44:39 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Jul 11 23:08:08 2015 +0200| [59a07df0673122b334af1f26367f6a49a0ec121b] | committer: Michael Niedermayer

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

based on code from libavutil/mem.c

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 libavcodec/utils.c |   13 ++++++++-----
 1 file 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;



More information about the ffmpeg-cvslog mailing list