fix: read item out of array blockinfo in miner tests (#5084)

This array contains 119 items and all of them are used.
But during test created one extra block that also need `blockinfo`.
It is UB and trigger address sanitizer.
This commit is contained in:
Konstantin Akimov 2022-11-30 23:20:12 +07:00 committed by GitHub
parent 305abe91f9
commit 09f91c0e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,6 +88,7 @@ constexpr static struct {
{0, 0x40045af7}, {0, 0x6000df7a}, {0, 0xe00131a1}, {0, 0x40021386},
{0, 0xa00891b5}, {0, 0x60007854}, {0, 0x60021730}
};
constexpr static size_t blockinfo_size = sizeof(blockinfo) / sizeof(blockinfo[0]);
static CBlockIndex CreateBlockIndex(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
@ -230,7 +231,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
std::vector<CTransactionRef> txFirst;
auto createAndProcessEmptyBlock = [&]() {
int i = ::ChainActive().Height();
int i = ::ChainActive().Height() % blockinfo_size;
CBlock *pblock = &pemptyblocktemplate->block; // pointer for convenience
{
LOCK(cs_main);