diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-02-23 12:00:41 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-02-25 11:11:07 +0000 |
commit | 7d88d8f27c96476ce6d627822d2418edd232e32d (patch) | |
tree | 39869f3820c4bcf6d26293d8ef056490e348f54f /src/crypto/tree-hash.c | |
parent | Merge pull request #4988 (diff) | |
download | monero-7d88d8f27c96476ce6d627822d2418edd232e32d.tar.xz |
discontinue use of alloca
NetBSD emits:
warning: Warning: reference to the libc supplied alloca(3); this most likely will not work. Please use the compiler provided version of alloca(3), by supplying the appropriate compiler flags (e.g. not -std=c89).
and man 3 alloca says:
Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi, -std=c89, -std=c99, or the
-std=c11 option is given and the header <alloca.h> is not included. Otherwise, (without an -ansi or -std=c* option) the glibc version of
<stdlib.h> includes <alloca.h> and that contains the lines:
#ifdef __GNUC__
#define alloca(size) __builtin_alloca (size)
#endif
It looks like alloca is a bad idea in modern C/C++, so we use
VLAs for C and std::vector for C++.
Diffstat (limited to 'src/crypto/tree-hash.c')
-rw-r--r-- | src/crypto/tree-hash.c | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/crypto/tree-hash.c b/src/crypto/tree-hash.c index b2dc3ffb2..2d9245233 100644 --- a/src/crypto/tree-hash.c +++ b/src/crypto/tree-hash.c @@ -34,15 +34,6 @@ #include "hash-ops.h" -#ifdef _MSC_VER -#include <malloc.h> -#elif !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) \ - && !defined(__NetBSD__) - #include <alloca.h> -#else - #include <stdlib.h> -#endif - /*** * Round to power of two, for count>=3 and for count being not too large (as reasonable for tree hash calculations) */ @@ -91,9 +82,8 @@ void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) { size_t cnt = tree_hash_cnt( count ); - char (*ints)[HASH_SIZE]; - size_t ints_size = cnt * HASH_SIZE; - ints = alloca(ints_size); memset( ints , 0 , ints_size); // allocate, and zero out as extra protection for using uninitialized mem + char ints[cnt][HASH_SIZE]; + memset(ints, 0 , sizeof(ints)); // zero out as extra protection for using uninitialized mem memcpy(ints, hashes, (2 * cnt - count) * HASH_SIZE); |