[FFmpeg-devel] [PATCH 3/3] random_seed: Replace a VLA with a heap alloc
Derek Buitenhuis
derek.buitenhuis at gmail.com
Fri Sep 7 16:38:17 CEST 2012
Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
libavutil/random_seed.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index d56280d..c6ffe57 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -23,6 +23,7 @@
#include <math.h>
#include <time.h>
#include <string.h>
+#include <errno.h>
#include "timer.h"
#include "random_seed.h"
#include "sha.h"
@@ -47,14 +48,19 @@ static int read_random(uint32_t *dst, const char *file)
static uint32_t get_generic_seed(void)
{
- uint8_t tmp[av_sha_size];
- struct AVSHA *sha = (void*)tmp;
+ uint8_t *tmp;
+ struct AVSHA *sha;
clock_t last_t = 0;
static uint64_t i = 0;
static uint32_t buffer[512] = {0};
unsigned char digest[32];
uint64_t last_i = i;
+ tmp = malloc(av_sha_size);
+ if (!tmp)
+ return ENOMEM;
+ sha = (void *) tmp;
+
if(TEST){
memset(buffer, 0, sizeof(buffer));
last_i = i = 0;
@@ -84,6 +90,9 @@ static uint32_t get_generic_seed(void)
av_sha_init(sha, 160);
av_sha_update(sha, (uint8_t*)buffer, sizeof(buffer));
av_sha_final(sha, digest);
+
+ free(tmp);
+
return AV_RB32(digest) + AV_RB32(digest+32);
}
--
1.7.9.5
More information about the ffmpeg-devel
mailing list