diff options
author | merge-script <fanquake@gmail.com> | 2024-08-02 10:50:34 +0100 |
---|---|---|
committer | merge-script <fanquake@gmail.com> | 2024-08-02 10:50:34 +0100 |
commit | 8e1bd17252e660ea3f515673a6d330d41c8a96d7 (patch) | |
tree | 70c27587ac93b48859a9b90634885e7f66b2a1a0 /src/rpc | |
parent | 9774a958b501a6d439a734e18b29e04f59f973f6 (diff) | |
parent | 2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d (diff) |
Merge bitcoin/bitcoin#30544: rpc: fix maybe-uninitialized compile warning in getchaintxstats
2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d 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 2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d
theStack:
ACK 2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d
tdb3:
ACK 2e86f2b2019ea0edbd89dd3fd13540c5bbfa104d
Tree-SHA512: c087e8f1cd68dd8df734a8400d30a95abe57ebd56cd53aef4230e425b33a23aa55b3af42abfd162e3be8c937a4c27e56abb70a4fedb10e2df64d52d577e0f262
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/blockchain.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e47e895214..9772b26aea 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); } } } |