summaryrefslogtreecommitdiff
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-01-15 14:26:55 +0100
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2012-01-17 20:16:35 +0100
commit3b55429d5692dd782d8b3ce6a19819305157d1b8 (patch)
tree489c7014c1e3843253cb17e53f3d3950967b312f /libavcodec/utils.c
parenta129622390fca8a298c3b121f42b2d15910b9b22 (diff)
Add and use av_fast_padded_malloc.
The same as av_fast_malloc but uses av_mallocz and keeps extra always-0 padding. This does not mean the memory will be 0-initialized after each call, but actually only after each growth of the buffer. However this makes sure that a) all data anywhere in the buffer is always initialized b) the padding is always 0 c) the user does not have to bother with adding the padding themselves Fixes another valgrind warning about use of uninitialized data, this time with fate-vsynth1-jpegls. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 657eb5b932..ccccd54acc 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -69,16 +69,34 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
return ptr;
}
-void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
{
void **p = ptr;
if (min_size < *size)
- return;
+ return 0;
min_size= FFMAX(17*min_size/16 + 32, min_size);
av_free(*p);
- *p = av_malloc(min_size);
+ *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
if (!*p) min_size = 0;
*size= min_size;
+ return 1;
+}
+
+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+{
+ ff_fast_malloc(ptr, size, min_size, 0);
+}
+
+void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
+{
+ uint8_t **p = ptr;
+ if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
+ *p = NULL;
+ *size = 0;
+ return;
+ }
+ if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
+ memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
}
/* encoder management */