From: Erkki Seppälä <erkki.seppala....@nokia.com> This allows copying an array so that is compatible with the array reallocation functions. av_memdup won't do, as it uses av_malloc underneath, but this one uses av_realloc_array for the allocation.
Signed-off-by: Erkki Seppälä <erkki.seppala....@nokia.com> Signed-off-by: OZOPlayer <oz...@nokia.com> --- libavutil/mem.c | 11 +++++++++++ libavutil/mem.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/libavutil/mem.c b/libavutil/mem.c index 1a8fc21..c74374e 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -307,6 +307,17 @@ void *av_memdup(const void *p, size_t size) return ptr; } +void *av_arraydup(const void *p, size_t nmemb, size_t size) +{ + void *ptr = NULL; + if (p) { + ptr = av_realloc_array(NULL, nmemb, size); + if (ptr) + memcpy(ptr, p, nmemb * size); + } + return ptr; +} + int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem) { void **tab; diff --git a/libavutil/mem.h b/libavutil/mem.h index 7f0c610..08ed520 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -514,6 +514,17 @@ char *av_strndup(const char *s, size_t len) av_malloc_attrib; void *av_memdup(const void *p, size_t size); /** + * Duplicate the array p. This array is compatible with the av_realloc + * functions. + * @param p array to be duplicated + * @param nmemb number of elements in the array + * @param size size of an element in the array + * @return Pointer to a newly allocated array containing a + * copy of p or NULL if the buffer cannot be allocated. + */ +void *av_arraydup(const void *p, size_t nmemb, size_t size); + +/** * Overlapping memcpy() implementation. * * @param dst Destination buffer -- 2.7.4 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel