From 17707db939cb09a16c002d226152e71fce9289f2 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Wed, 21 Aug 2024 14:06:49 -0400 Subject: [PATCH] Fix maybe-uninitialized warning in IsSpentKey --- src/wallet/wallet.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5584b43520aa6..8df39b9f75dc2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1039,21 +1039,20 @@ bool CWallet::IsSpentKey(const CScript& scriptPubKey) const return true; } - LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan(); - if (!spk_man) return false; - - for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) { - WitnessV0KeyHash wpkh_dest(keyid); - if (IsAddressPreviouslySpent(wpkh_dest)) { - return true; - } - ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); - if (IsAddressPreviouslySpent(sh_wpkh_dest)) { - return true; - } - PKHash pkh_dest(keyid); - if (IsAddressPreviouslySpent(pkh_dest)) { - return true; + if (LegacyScriptPubKeyMan* spk_man = GetLegacyScriptPubKeyMan()) { + for (const auto& keyid : GetAffectedKeys(scriptPubKey, *spk_man)) { + WitnessV0KeyHash wpkh_dest(keyid); + if (IsAddressPreviouslySpent(wpkh_dest)) { + return true; + } + ScriptHash sh_wpkh_dest(GetScriptForDestination(wpkh_dest)); + if (IsAddressPreviouslySpent(sh_wpkh_dest)) { + return true; + } + PKHash pkh_dest(keyid); + if (IsAddressPreviouslySpent(pkh_dest)) { + return true; + } } } return false;