Skip to content

Commit 2e86f2b

Browse files
committed
rpc: fix maybe-uninitialized compile warning in getchaintxstats
This resolves the compiler warning about potential uninitialized use of window_tx_count introduced in fa2dada.
1 parent 30cef53 commit 2e86f2b

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)