Merge #17235: tests: Skip unnecessary fuzzer initialisation. Hold ECCVerifyHandle only when needed.

c2f964a674 tests: Remove Cygwin WinMain workaround (practicalswift)
db4bd32cc3 tests: Skip unnecessary fuzzer initialisation. Hold ECCVerifyHandle only when needed. (practicalswift)

Pull request description:

  Skip unnecessary fuzzer initialisation. Hold `ECCVerifyHandle` only when needed.

  As suggested by MarcoFalke in https://github.com/bitcoin/bitcoin/pull/17018#discussion_r336645391.

Top commit has no ACKs.

Tree-SHA512: 598da44859d736e3fdc143b93e07f444d8ad19dfdab0cfe7c6ccff8644e862664d869337dfe6b49416ed09a0024e4a5f2220ca6246de568f9e9227d721baa28e
This commit is contained in:
MarcoFalke 2019-10-24 08:31:28 -04:00
commit d53828cb79
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
2 changed files with 11 additions and 12 deletions

View file

@ -12,6 +12,7 @@
#include <net.h>
#include <primitives/block.h>
#include <protocol.h>
#include <pubkey.h>
#include <streams.h>
#include <undo.h>
#include <version.h>
@ -23,6 +24,12 @@
#include <test/fuzz/fuzz.h>
void initialize()
{
// Fuzzers using pubkey must hold an ECCVerifyHandle.
static const auto verify_handle = MakeUnique<ECCVerifyHandle>();
}
void test_one_input(const std::vector<uint8_t>& buffer)
{
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);

View file

@ -4,11 +4,9 @@
#include <test/fuzz/fuzz.h>
#include <cstdint>
#include <unistd.h>
#include <pubkey.h>
#include <util/memory.h>
#include <vector>
static bool read_stdin(std::vector<uint8_t>& data)
{
@ -23,10 +21,8 @@ static bool read_stdin(std::vector<uint8_t>& data)
}
// Default initialization: Override using a non-weak initialize().
__attribute__((weak))
void initialize()
__attribute__((weak)) void initialize()
{
const static auto verify_handle = MakeUnique<ECCVerifyHandle>();
}
// This function is used by libFuzzer
@ -44,13 +40,9 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
return 0;
}
// Disabled under WIN32 due to clash with Cygwin's WinMain.
#ifndef WIN32
// Declare main(...) "weak" to allow for libFuzzer linking. libFuzzer provides
// the main(...) function.
__attribute__((weak))
#endif
int main(int argc, char **argv)
__attribute__((weak)) int main(int argc, char** argv)
{
initialize();
#ifdef __AFL_INIT