mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-24 03:39:45 +00:00
mem: Consistently return NULL for av_malloc(0)
Plain POSIX malloc(0) is allowed to return either NULL or a non-NULL pointer. The calling code should be ready to handle a NULL return as a correct return (instead of a failure) if the size to allocate was 0 - this makes sure the condition is handled in a consistent way across platforms. This also avoids calling posix_memalign(&ptr, 32, 0) on OS X, which returns an invalid pointer (a non-NULL pointer that causes crashes when passed to av_free). Abort in debug mode, to help track down issues related to incorrect handling of this case. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
e36b25d1df
commit
14f063d294
@ -68,8 +68,10 @@ void *av_malloc(size_t size)
|
||||
long diff;
|
||||
#endif
|
||||
|
||||
assert(size);
|
||||
|
||||
/* let's disallow possible ambiguous cases */
|
||||
if(size > (INT_MAX-32) )
|
||||
if (size > (INT_MAX-32) || !size)
|
||||
return NULL;
|
||||
|
||||
#if CONFIG_MEMALIGN_HACK
|
||||
|
Loading…
Reference in New Issue
Block a user