From: Laurent Aimar <[email protected]>

Signed-off-by: Diego Biurrun <[email protected]>
---
 libavutil/mem.c |  7 +++++++
 libavutil/mem.h | 12 ++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 0f506d3..8231431 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -193,6 +193,13 @@ void *av_mallocz(size_t size)
     return ptr;
 }
 
+void *av_calloc(size_t nmemb, size_t size)
+{
+    if (size <= 0 || nmemb >= INT_MAX / size)
+        return NULL;
+    return av_mallocz(nmemb * size);
+}
+
 char *av_strdup(const char *s)
 {
     char *ptr = NULL;
diff --git a/libavutil/mem.h b/libavutil/mem.h
index f3cf56c..b72692b 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -210,6 +210,18 @@ av_alloc_size(1, 2) static inline void 
*av_mallocz_array(size_t nmemb, size_t si
 }
 
 /**
+ * Allocate a block of nmemb * size bytes with alignment suitable for all
+ * memory accesses (including vectors if available on the CPU) and
+ * zero all the bytes of the block.
+ * The allocation will fail if nmemb * size is greater than or equal
+ * to INT_MAX.
+ * @param nmemb Number of elements
+ * @param size  Size of the single element
+ * @return Pointer to the allocated block, NULL if it cannot be allocated.
+ */
+void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
+
+/**
  * Duplicate the string s.
  * @param s string to be duplicated
  * @return Pointer to a newly-allocated string containing a
-- 
2.1.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to