From 2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d Mon Sep 17 00:00:00 2001 From: Michael Dietz Date: Mon, 29 Jul 2024 12:14:27 -0500 Subject: [PATCH] rpc: fix maybe-uninitialized compile warning in getchaintxstats This resolves the compiler warning about potential uninitialized use of window_tx_count introduced in fa2dada. --- src/rpc/blockchain.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bcc715057af..4dea65e7479 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1722,9 +1722,6 @@ static RPCHelpMan getchaintxstats() const CBlockIndex& past_block{*CHECK_NONFATAL(pindex->GetAncestor(pindex->nHeight - blockcount))}; const int64_t nTimeDiff{pindex->GetMedianTimePast() - past_block.GetMedianTimePast()}; - const auto window_tx_count{ - (pindex->nChainTx != 0 && past_block.nChainTx != 0) ? std::optional{pindex->nChainTx - past_block.nChainTx} : std::nullopt, - }; UniValue ret(UniValue::VOBJ); ret.pushKV("time", (int64_t)pindex->nTime); @@ -1736,10 +1733,11 @@ static RPCHelpMan getchaintxstats() ret.pushKV("window_block_count", blockcount); if (blockcount > 0) { ret.pushKV("window_interval", nTimeDiff); - if (window_tx_count) { - ret.pushKV("window_tx_count", *window_tx_count); + if (pindex->nChainTx != 0 && past_block.nChainTx != 0) { + const auto window_tx_count = pindex->nChainTx - past_block.nChainTx; + ret.pushKV("window_tx_count", window_tx_count); if (nTimeDiff > 0) { - ret.pushKV("txrate", double(*window_tx_count) / nTimeDiff); + ret.pushKV("txrate", double(window_tx_count) / nTimeDiff); } } }