diff options
author | Martin Storsjö <martin@martin.st> | 2013-06-03 12:31:46 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2013-06-04 15:04:08 +0300 |
commit | fc962d4e7a7c3d799d9364d5427564c22ee3880c (patch) | |
tree | 4762a5e0b89bc406dce0c966c052393d7ae65859 /libavutil/mem.h | |
parent | 9683e37cd5c556c9974e78fba344ede4f33afd18 (diff) | |
download | ffmpeg-fc962d4e7a7c3d799d9364d5427564c22ee3880c.tar.gz |
mem: Add av_realloc_array and av_reallocp_array
These help avoiding overflows and simplify error handling.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavutil/mem.h')
-rw-r--r-- | libavutil/mem.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libavutil/mem.h b/libavutil/mem.h index 8f4722447d..8a4fcd90ae 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -112,6 +112,32 @@ av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t siz void *av_realloc(void *ptr, size_t size) av_alloc_size(2); /** + * Allocate or reallocate an array. + * If ptr is NULL and nmemb > 0, allocate a new block. If + * nmemb is zero, free the memory block pointed to by ptr. + * @param ptr Pointer to a memory block already allocated with + * av_malloc(z)() or av_realloc() or NULL. + * @param nmemb Number of elements + * @param size Size of the single element + * @return Pointer to a newly reallocated block or NULL if the block + * cannot be reallocated or the function is used to free the memory block. + */ +av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size); + +/** + * Allocate or reallocate an array. + * If *ptr is NULL and nmemb > 0, allocate a new block. If + * nmemb is zero, free the memory block pointed to by ptr. + * @param ptr Pointer to a pointer to a memory block already allocated + * with av_malloc(z)() or av_realloc(), or pointer to a pointer to NULL. + * The pointer is updated on success, or freed on failure. + * @param nmemb Number of elements + * @param size Size of the single element + * @return Zero on success, an AVERROR error code on failure. + */ +av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size); + +/** * Free a memory block which has been allocated with av_malloc(z)() or * av_realloc(). * @param ptr Pointer to the memory block which should be freed. |