Skip to content

Commit 8e1bd17

Browse files
committed
Merge bitcoin#30544: rpc: fix maybe-uninitialized compile warning in getchaintxstats
2e86f2b rpc: fix maybe-uninitialized compile warning in getchaintxstats (Michael Dietz) Pull request description: This resolves the compiler warning about potential uninitialized use of window_tx_count introduced in fa2dada. The warning: ``` CXX rpc/libbitcoin_node_a-blockchain.o rpc/blockchain.cpp: In function ‘getchaintxstats()::<lambda(const RPCHelpMan&, const JSONRPCRequest&)>’: rpc/blockchain.cpp:1742:38: warning: ‘*(std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>*)((char*)&window_tx_count + offsetof(const std::optional<unsigned int>,std::optional<unsigned int>::<unnamed>.std::_Optional_base<unsigned int, true, true>::<unnamed>)).std::_Optional_payload_base<unsigned int>::_Storage<unsigned int, true>::_M_value’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1742 | ret.pushKV("txrate", double(*window_tx_count) / nTimeDiff); | ``` ACKs for top commit: maflcko: lgtm ACK 2e86f2b theStack: ACK 2e86f2b tdb3: ACK 2e86f2b Tree-SHA512: c087e8f1cd68dd8df734a8400d30a95abe57ebd56cd53aef4230e425b33a23aa55b3af42abfd162e3be8c937a4c27e56abb70a4fedb10e2df64d52d577e0f262
2 parents 9774a95 + 2e86f2b commit 8e1bd17

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,6 @@ static RPCHelpMan getchaintxstats()
17221722

17231723
const CBlockIndex& past_block{*CHECK_NONFATAL(pindex->GetAncestor(pindex->nHeight - blockcount))};
17241724
const int64_t nTimeDiff{pindex->GetMedianTimePast() - past_block.GetMedianTimePast()};
1725-
const auto window_tx_count{
1726-
(pindex->nChainTx != 0 && past_block.nChainTx != 0) ? std::optional{pindex->nChainTx - past_block.nChainTx} : std::nullopt,
1727-
};
17281725

17291726
UniValue ret(UniValue::VOBJ);
17301727
ret.pushKV("time", (int64_t)pindex->nTime);
@@ -1736,10 +1733,11 @@ static RPCHelpMan getchaintxstats()
17361733
ret.pushKV("window_block_count", blockcount);
17371734
if (blockcount > 0) {
17381735
ret.pushKV("window_interval", nTimeDiff);
1739-
if (window_tx_count) {
1740-
ret.pushKV("window_tx_count", *window_tx_count);
1736+
if (pindex->nChainTx != 0 && past_block.nChainTx != 0) {
1737+
const auto window_tx_count = pindex->nChainTx - past_block.nChainTx;
1738+
ret.pushKV("window_tx_count", window_tx_count);
17411739
if (nTimeDiff > 0) {
1742-
ret.pushKV("txrate", double(*window_tx_count) / nTimeDiff);
1740+
ret.pushKV("txrate", double(window_tx_count) / nTimeDiff);
17431741
}
17441742
}
17451743
}

0 commit comments

Comments
 (0)