summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/mem.h37
-rw-r--r--libavutil/version.h2
2 files changed, 36 insertions, 3 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
diff --git a/libavutil/version.h b/libavutil/version.h
index b456d825a1..5ae7367d4d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -39,7 +39,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 64
+#define LIBAVUTIL_VERSION_MINOR 65
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \