Skip to content

Commit 7e1b968

Browse files
ryanofskyachow101
authored andcommitted
qt: Avoid crash on startup if int specified in settings.json
Fix GUI startup crash reported by Rspigler in bitcoin/bitcoin#24457 that happens if settings.json contains an integer value for any of the configuration options which GUI settings can currently clash with (-dbcache, -par, -spendzeroconfchange, -signer, -upnp, -natpmp, -listen, -server, -proxy, -proxy, -onion, -onion, -lang, and -prune). Fix is a one-line change in ArgsManager::GetArg. Github-Pull: bitcoin/bitcoin#24498 Rebased-From: 5b1aae1
1 parent 4607f70 commit 7e1b968

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/qt/test/optiontests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
//! Entry point for BitcoinApplication tests.
1616
void OptionTests::optionTests()
1717
{
18-
// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Check
19-
// if setting an integer prune value causes an exception to be thrown in
20-
// the OptionsModel constructor.
18+
// Test regression https://github.com/bitcoin/bitcoin/issues/24457. Ensure
19+
// that setting integer prune value doesn't cause an exception to be thrown
20+
// in the OptionsModel constructor
2121
gArgs.LockSettings([&](util::Settings& settings) {
2222
settings.forced_settings.erase("prune");
2323
settings.rw_settings["prune"] = 3814;
2424
});
2525
gArgs.WriteSettingsFile();
26-
QVERIFY_EXCEPTION_THROWN(OptionsModel{}, std::runtime_error);
26+
OptionsModel{};
2727
gArgs.LockSettings([&](util::Settings& settings) {
2828
settings.rw_settings.erase("prune");
2929
});

src/test/getarg_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,21 @@ BOOST_AUTO_TEST_CASE(setting_args)
9898

9999
set_foo(99);
100100
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "99");
101-
BOOST_CHECK_THROW(args.GetArg("foo", "default"), std::runtime_error);
101+
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "99");
102102
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 99);
103103
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
104104
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
105105

106106
set_foo(3.25);
107107
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "3.25");
108-
BOOST_CHECK_THROW(args.GetArg("foo", "default"), std::runtime_error);
108+
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "3.25");
109109
BOOST_CHECK_THROW(args.GetIntArg("foo", 100), std::runtime_error);
110110
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
111111
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);
112112

113113
set_foo(0);
114114
BOOST_CHECK_EQUAL(args.GetSetting("foo").write(), "0");
115-
BOOST_CHECK_THROW(args.GetArg("foo", "default"), std::runtime_error);
115+
BOOST_CHECK_EQUAL(args.GetArg("foo", "default"), "0");
116116
BOOST_CHECK_EQUAL(args.GetIntArg("foo", 100), 0);
117117
BOOST_CHECK_THROW(args.GetBoolArg("foo", true), std::runtime_error);
118118
BOOST_CHECK_THROW(args.GetBoolArg("foo", false), std::runtime_error);

src/util/system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ bool ArgsManager::IsArgNegated(const std::string& strArg) const
588588
std::string ArgsManager::GetArg(const std::string& strArg, const std::string& strDefault) const
589589
{
590590
const util::SettingsValue value = GetSetting(strArg);
591-
return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str();
591+
return value.isNull() ? strDefault : value.isFalse() ? "0" : value.isTrue() ? "1" : value.isNum() ? value.getValStr() : value.get_str();
592592
}
593593

594594
int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const

0 commit comments

Comments
 (0)