From 0e003d8c91b85a2ec49f7a653f9c6f93d025bf5a Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Tue, 10 Jul 2012 03:49:44 +0000
Subject: [PATCH] lavc: add av_fast_padded_mallocz

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 doc/APIchanges       |  3 +++
 libavcodec/avcodec.h |  6 ++++++
 libavcodec/utils.c   | 12 ++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index e17aae73aaf..65870107c94 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-07-10 - xxxxxxx - lavc 54.33.100
+  Add av_fast_padded_mallocz().
+
 2012-07-10 - xxxxxxx - lavfi 3.2.0 - avfilter.h
   Add init_opaque() callback to AVFilter struct.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c850963a976..80bd75e7782 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4601,6 +4601,12 @@ void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
  */
 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
 
+/**
+ * Same behaviour av_fast_padded_malloc except that buffer will always
+ * be 0-initialized after call.
+ */
+void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
+
 /**
  * Encode extradata length to a buffer. Used by xiph codecs.
  *
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ddd63db3319..a326815bc42 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -100,6 +100,18 @@ void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
         memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 }
 
+void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
+{
+    uint8_t **p = ptr;
+    if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
+        av_freep(p);
+        *size = 0;
+        return;
+    }
+    if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
+        memset(*p, 0, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
+}
+
 /* encoder management */
 static AVCodec *first_avcodec = NULL;
 
-- 
GitLab