diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-07-16 01:32:52 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-07-16 01:32:52 +0200 |
commit | fbe02459dc4f3c8f4d758c1a90ed8e35a800f3b9 (patch) | |
tree | 66263011ff0784ce9a33b697a117516de48401fa /libavutil/mem.h | |
parent | 9a1963fbb872f08222a5b73fe96931708ca32732 (diff) | |
parent | b4675d0fbf6606ab737e81c3c0fe6a05c8764334 (diff) | |
download | ffmpeg-fbe02459dc4f3c8f4d758c1a90ed8e35a800f3b9.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
configure: Check for CommandLineToArgvW
vc1dec: Do not use random pred_flag if motion vector data is skipped
vp8: Enclose pthread function calls in ifdefs
snow: refactor code to work around a compiler bug in MSVC.
vp8: Include the thread headers before using the pthread types
configure: Check for getaddrinfo in ws2tcpip.h, too
vp8: implement sliced threading
vp8: move data from VP8Context->VP8Macroblock
vp8: refactor decoding a single mb_row
doc: update api changes with the right commit hashes
mem: introduce av_malloc_array and av_mallocz_array
Conflicts:
configure
doc/APIchanges
libavcodec/vp8.c
libavutil/mem.h
libavutil/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mem.h')
-rw-r--r-- | libavutil/mem.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/libavutil/mem.h b/libavutil/mem.h index c6c907ea08..4f1e6a0cdf 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -64,9 +64,9 @@ #endif #if AV_GCC_VERSION_AT_LEAST(4,3) - #define av_alloc_size(n) __attribute__((alloc_size(n))) + #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) #else - #define av_alloc_size(n) + #define av_alloc_size(...) #endif /** @@ -80,6 +80,22 @@ void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1); /** + * Helper function to allocate a block of size * nmemb bytes with + * using av_malloc() + * @param nmemb Number of elements + * @param size Size of the single element + * @return Pointer to the allocated block, NULL if the block cannot + * be allocated. + * @see av_malloc() + */ +av_alloc_size(1,2) static inline void *av_malloc_array(size_t nmemb, size_t size) +{ + if (size <= 0 || nmemb >= INT_MAX / size) + return NULL; + return av_malloc(nmemb * size); +} + +/** * Allocate or reallocate a block of memory. * If ptr is NULL and size > 0, allocate a new block. If * size is zero, free the memory block pointed to by ptr. @@ -136,6 +152,23 @@ void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1); void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib; /** + * Helper function to allocate a block of size * nmemb bytes with + * using av_mallocz() + * @param nmemb Number of elements + * @param size Size of the single element + * @return Pointer to the allocated block, NULL if the block cannot + * be allocated. + * @see av_mallocz() + * @see av_malloc_array() + */ +av_alloc_size(1,2) static inline void *av_mallocz_array(size_t nmemb, size_t size) +{ + if (size <= 0 || nmemb >= INT_MAX / size) + return NULL; + return av_mallocz(nmemb * size); +} + +/** * Duplicate the string s. * @param s string to be duplicated * @return Pointer to a newly allocated string containing a |