Commit fa73358c authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '60392480'

* commit '60392480':
  mem: fix pointer pointer aliasing violations

Conflicts:
	libavutil/mem.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 9bacb576 60392480
...@@ -184,21 +184,22 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) ...@@ -184,21 +184,22 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
int av_reallocp(void *ptr, size_t size) int av_reallocp(void *ptr, size_t size)
{ {
void **ptrptr = ptr; void *val;
void *ret;
if (!size) { if (!size) {
av_freep(ptr); av_freep(ptr);
return 0; return 0;
} }
ret = av_realloc(*ptrptr, size);
if (!ret) { memcpy(&val, ptr, sizeof(val));
val = av_realloc(val, size);
if (!val) {
av_freep(ptr); av_freep(ptr);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
*ptrptr = ret; memcpy(ptr, &val, sizeof(val));
return 0; return 0;
} }
...@@ -211,10 +212,14 @@ void *av_realloc_array(void *ptr, size_t nmemb, size_t size) ...@@ -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) int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
{ {
void **ptrptr = ptr; void *val;
*ptrptr = av_realloc_f(*ptrptr, nmemb, size);
if (!*ptrptr && nmemb && size) 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 AVERROR(ENOMEM);
return 0; return 0;
} }
...@@ -235,9 +240,11 @@ void av_free(void *ptr) ...@@ -235,9 +240,11 @@ void av_free(void *ptr)
void av_freep(void *arg) void av_freep(void *arg)
{ {
void **ptr = (void **)arg; void *val;
av_free(*ptr);
*ptr = NULL; memcpy(&val, arg, sizeof(val));
memcpy(arg, &(void *){ NULL }, sizeof(val));
av_free(val);
} }
void *av_mallocz(size_t size) void *av_mallocz(size_t size)
......
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