[FFmpeg-devel] [PATCH] avutil/mem: replace remaining void **/*** casts by memcpy()

Michael Niedermayer michaelni at gmx.at
Sun Feb 1 15:27:34 CET 2015


This is similar to 60392480181f24ebf3ab48d8ac3614705de90152

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavutil/mem.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 155569e..5fd2395 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -307,11 +307,12 @@ void *av_memdup(const void *p, size_t size)
 
 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
 {
-    void **tab = *(void ***)tab_ptr;
+    void **tab;
+    memcpy(&tab, tab_ptr, sizeof(tab));
 
     AV_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
         tab[*nb_ptr] = elem;
-        *(void ***)tab_ptr = tab;
+        memcpy(tab_ptr, &tab, sizeof(tab));
     }, {
         return AVERROR(ENOMEM);
     });
@@ -320,11 +321,12 @@ int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
 
 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
 {
-    void **tab = *(void ***)tab_ptr;
+    void **tab;
+    memcpy(&tab, tab_ptr, sizeof(tab));
 
     AV_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
         tab[*nb_ptr] = elem;
-        *(void ***)tab_ptr = tab;
+        memcpy(tab_ptr, &tab, sizeof(tab));
     }, {
         *nb_ptr = 0;
         av_freep(tab_ptr);
@@ -494,13 +496,15 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
 
 static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
 {
-    void **p = ptr;
+    void *val;
+
     if (min_size < *size)
         return 0;
     min_size = FFMAX(17 * 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;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list