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