summaryrefslogtreecommitdiff
path: root/libavutil/mem.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-02-01 13:52:22 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-02-01 13:52:22 +0100
commitfa73358c9bfd3cb433c6f31a31fc4128c762d809 (patch)
tree1eab3942152096fde24c4e69301b7e7f4d7f3ded /libavutil/mem.c
parent9bacb576bcdfc86473c04dba8296426fe185ad07 (diff)
parent60392480181f24ebf3ab48d8ac3614705de90152 (diff)
downloadffmpeg-fa73358c9bfd3cb433c6f31a31fc4128c762d809.tar.gz
Merge commit '60392480181f24ebf3ab48d8ac3614705de90152'
* commit '60392480181f24ebf3ab48d8ac3614705de90152': mem: fix pointer pointer aliasing violations Conflicts: libavutil/mem.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r--libavutil/mem.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 35a82e8a2d..155569e224 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -184,21 +184,22 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
int av_reallocp(void *ptr, size_t size)
{
- void **ptrptr = ptr;
- void *ret;
+ void *val;
if (!size) {
av_freep(ptr);
return 0;
}
- ret = av_realloc(*ptrptr, size);
- if (!ret) {
+ memcpy(&val, ptr, sizeof(val));
+ val = av_realloc(val, size);
+
+ if (!val) {
av_freep(ptr);
return AVERROR(ENOMEM);
}
- *ptrptr = ret;
+ memcpy(ptr, &val, sizeof(val));
return 0;
}
@@ -211,10 +212,14 @@ void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
{
- void **ptrptr = ptr;
- *ptrptr = av_realloc_f(*ptrptr, nmemb, size);
- if (!*ptrptr && nmemb && size)
+ void *val;
+
+ memcpy(&val, ptr, sizeof(val));
+ val = av_realloc_f(val, nmemb, size);
+ memcpy(ptr, &val, sizeof(val));
+ if (!val && nmemb && size)
return AVERROR(ENOMEM);
+
return 0;
}
@@ -235,9 +240,11 @@ void av_free(void *ptr)
void av_freep(void *arg)
{
- void **ptr = (void **)arg;
- av_free(*ptr);
- *ptr = NULL;
+ void *val;
+
+ memcpy(&val, arg, sizeof(val));
+ memcpy(arg, &(void *){ NULL }, sizeof(val));
+ av_free(val);
}
void *av_mallocz(size_t size)