[FFmpeg-cvslog] Add av_calloc() helper.

Laurent Aimar git at videolan.org
Sat Oct 1 21:38:49 CEST 2011


ffmpeg | branch: release/0.8 | Laurent Aimar <fenrir at videolan.org> | Sat Sep 24 18:39:13 2011 +0200| [5681d74aaf7e241303aa8785dcdc9b6b437e1573] | committer: Michael Niedermayer

Add av_calloc() helper.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit ccecab4a0d7f3f4f296551c2e22bbf12af7d14e8)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5681d74aaf7e241303aa8785dcdc9b6b437e1573
---

 libavutil/mem.c |    7 +++++++
 libavutil/mem.h |   12 ++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/libavutil/mem.c b/libavutil/mem.c
index 87c2008..44bfc8c 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -168,6 +168,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 7c30e16..be8a8bf 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -107,6 +107,18 @@ void av_free(void *ptr);
 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
 
 /**
+ * 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
+ * @param size
+ * @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



More information about the ffmpeg-cvslog mailing list