[FFmpeg-devel] [PATCH 3/3] random_seed: Replace a VLA with a heap alloc

Michael Niedermayer michaelni at gmx.at
Fri Sep 7 19:35:59 CEST 2012


On Fri, Sep 07, 2012 at 10:38:17AM -0400, Derek Buitenhuis wrote:
> 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;

i would suggest
uint8_t tmp[120];
...
av_assert0(sizeof(tmp) >= av_sha_size)

this would be simpler and completely avoid variable allocation

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120907/7478594f/attachment.asc>


More information about the ffmpeg-devel mailing list