refactor: Make ThreadSafeMessageBox signal void
What changed, and why it matters
This is a small internal cleanup change in Bitcoin Core. It changes a message-box signal so it no longer returns a value, because the return value was always ignored. It also adds a compiler hint ([[nodiscard]]) to the GUI version to prevent accidentally ignoring its return value in the future. There is no security-relevant behavior change.
No security action needed. Treat as normal code-review/merge for a refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors CClientUIInterface::ThreadSafeMessageBox from returning bool to returning void, because callers always discarded the result and the non-GUI implementation always returned false. The signal wrapper is updated accordingly, and the Qt GUI’s static ThreadSafeMessageBox helper is annotated [[nodiscard]] while its return value is explicitly discarded with (void) in the lambda connecting it to the now-void signal. ThreadSafeQuestion remains bool-returning. This is a type-system cleanup with no functional or security impact.
Changed components
src/interfaces/node.hsrc/node/interface_ui.cppsrc/node/interface_ui.hsrc/noui.cppsrc/noui.hsrc/qt/bitcoingui.cppInspect captured patch +11 / −13
diff --git a/src/interfaces/node.h b/src/interfaces/node.h
index ad6298e6..8b8402ec 100644
--- a/src/interfaces/node.h
+++ b/src/interfaces/node.h
@@ -219,8 +219,7 @@ public:
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
//! Register handler for message box messages.
- using MessageBoxFn =
- std::function<bool(const bilingual_str& message, unsigned int style)>;
+ using MessageBoxFn = std::function<void(const bilingual_str& message, unsigned int style)>;
virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
//! Register handler for question messages.
diff --git a/src/node/interface_ui.cpp b/src/node/interface_ui.cpp
index 6b1fe72f..54b267c8 100644
--- a/src/node/interface_ui.cpp
+++ b/src/node/interface_ui.cpp
@@ -13,7 +13,7 @@ using util::MakeUnorderedList;
CClientUIInterface uiInterface;
struct UISignals {
- btcsignals::signal<CClientUIInterface::ThreadSafeMessageBoxSig, btcsignals::optional_last_value<bool>> ThreadSafeMessageBox;
+ btcsignals::signal<CClientUIInterface::ThreadSafeMessageBoxSig> ThreadSafeMessageBox;
btcsignals::signal<CClientUIInterface::ThreadSafeQuestionSig, btcsignals::optional_last_value<bool>> ThreadSafeQuestion;
btcsignals::signal<CClientUIInterface::InitMessageSig> InitMessage;
btcsignals::signal<CClientUIInterface::InitWalletSig> InitWallet;
@@ -45,7 +45,7 @@ ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
-bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, style).value_or(false);}
+void CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, style); }
bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, style).value_or(false);}
void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
void CClientUIInterface::InitWallet() { return g_ui_signals.InitWallet(); }
diff --git a/src/node/interface_ui.h b/src/node/interface_ui.h
index 8175683f..47e3da2c 100644
--- a/src/node/interface_ui.h
+++ b/src/node/interface_ui.h
@@ -72,7 +72,7 @@ public:
btcsignals::connection signal_name##_connect(std::function<signal_name##Sig> fn)
/** Show message box. */
- ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const bilingual_str& message, unsigned int style);
+ ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, void, const bilingual_str& message, unsigned int style);
/** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, style) and returns false. */
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const bilingual_str& message, const std::string& noninteractive_message, unsigned int style);
diff --git a/src/noui.cpp b/src/noui.cpp
index 12ebc401..ee61a099 100644
--- a/src/noui.cpp
+++ b/src/noui.cpp
@@ -17,7 +17,7 @@ btcsignals::connection noui_ThreadSafeMessageBoxConn;
btcsignals::connection noui_ThreadSafeQuestionConn;
btcsignals::connection noui_InitMessageConn;
-bool noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style)
+void noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style)
{
bool fSecure = style & CClientUIInterface::SECURE;
style &= ~CClientUIInterface::SECURE;
@@ -41,12 +41,12 @@ bool noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style)
}
tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
- return false;
}
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
{
- return noui_ThreadSafeMessageBox(Untranslated(message), style);
+ noui_ThreadSafeMessageBox(Untranslated(message), style);
+ return false; // Answer the question with false in the noui context
}
void noui_InitMessage(const std::string& message)
@@ -61,10 +61,9 @@ void noui_connect()
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
}
-bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, unsigned int style)
+void noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, unsigned int style)
{
LogInfo("%s", message.original);
- return false;
}
bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
diff --git a/src/noui.h b/src/noui.h
index 332346f5..71f284bd 100644
--- a/src/noui.h
+++ b/src/noui.h
@@ -10,7 +10,7 @@
struct bilingual_str;
/** Non-GUI handler, which logs and prints messages. */
-bool noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style);
+void noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style);
/** Non-GUI handler, which logs and prints questions. */
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style);
/** Non-GUI handler, which only logs a message. */
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 96ea3f4a..9d3f7ad6 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -1589,7 +1589,7 @@ void BitcoinGUI::showModalOverlay()
modalOverlay->toggleVisibility();
}
-static bool ThreadSafeMessageBox(BitcoinGUI* gui, const bilingual_str& message, unsigned int style)
+[[nodiscard]] static bool ThreadSafeMessageBox(BitcoinGUI* gui, const bilingual_str& message, unsigned int style)
{
bool modal = (style & CClientUIInterface::MODAL);
// The SECURE flag has no effect in the Qt GUI.
@@ -1621,7 +1621,7 @@ void BitcoinGUI::subscribeToCoreSignals()
{
// Connect signals to client
m_handler_message_box = m_node.handleMessageBox([this](const bilingual_str& message, unsigned int style) {
- return ThreadSafeMessageBox(this, message, style);
+ (void)ThreadSafeMessageBox(this, message, style);
});
m_handler_question = m_node.handleQuestion([this](const bilingual_str& message, const std::string& /*non_interactive_message*/, unsigned int style) {
return ThreadSafeMessageBox(this, message, style);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.