db_lmdb: avoid decoding data we do not need

This commit is contained in:
Crypto City 2021-11-17 11:54:14 +00:00
parent ade9fa1433
commit fa250ec167

View File

@ -7235,11 +7235,22 @@ void BlockchainLMDB::set_cc_flag_data(uint32_t id, const cc_flag_data_t &fd)
throw0(DB_ERROR(lmdb_error("Flag " + std::to_string(id) + " not found: ", result).c_str()));
mdb_cc_flag_data cfd;
#if 1
static_assert(sizeof(mdb_cc_flag_data::deleted) == 1, "deleted must be one byte");
if ((intptr_t)&cfd.deleted != (intptr_t)&cfd)
throw0(DB_ERROR("deleted must be the first field"));
if (v.mv_size == 0)
throw0(DB_ERROR("Flag data is empty"));
const bool deleted = *(const bool*)v.mv_data;
if (deleted)
throw0(DB_ERROR("Flag is deleted"));
#else
if (!read_flag_data(v, cfd))
throw0(DB_ERROR("Failed to deserialize flag data"));
if (cfd.deleted)
throw0(DB_ERROR("Flag is deleted"));
#endif
cfd.deleted = false;
cfd.owner = fd.owner;