Always prefer vararrays to alloca()

This commit is contained in:
Frank Denis 2017-12-12 22:27:21 +01:00
parent 2f56443631
commit 95a7dc5e46

View File

@ -21,22 +21,24 @@
# include <unistd.h>
#endif
#if HAVE_ALLOCA_H
# include <alloca.h>
#elif !defined(alloca)
# if defined(__GNUC__)
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# include <stddef.h>
# ifdef __cplusplus
#ifndef HAVE_C_VARARRAYS
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# elif !defined(alloca)
# if defined(__GNUC__)
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# else
# include <stddef.h>
# ifdef __cplusplus
extern "C"
# endif
# endif
void *alloca (size_t);
# endif
# endif
#endif
@ -128,11 +130,11 @@ sodium_memzero(void *const pnt, const size_t len)
void
sodium_stackzero(const size_t len)
{
#ifdef HAVE_ALLOCA
sodium_memzero(alloca(len), len);
#elif HAVE_C_VARARRAYS
#ifdef HAVE_C_VARARRAYS
unsigned char fodder[len];
sodium_memzero(fodder, len);
#elif HAVE_ALLOCA
sodium_memzero(alloca(len), len);
#endif
}