From 8bba1d2eb8dd77e973ee5dd6043d85929558e0a7 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Tue, 30 Dec 2025 03:15:43 +0530 Subject: [PATCH] fix: don't assume that successful `weightFromArg` links to valid index --- src/qt/optionsmodel.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 7666ca79ae16..4955ef47008d 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -564,16 +564,22 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const case FontScale: return settings.value("fontScale"); case FontWeightNormal: { - QFont::Weight weight{GUIUtil::g_font_registry.GetWeightNormalDefault()}; - GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight); - int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight); + int nIndex = [&]() -> int { + if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) { + return GUIUtil::g_font_registry.WeightToIdx(weight); + } + return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightNormalDefault()); + }(); assert(nIndex != -1); return nIndex; } case FontWeightBold: { - QFont::Weight weight{GUIUtil::g_font_registry.GetWeightBoldDefault()}; - GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight); - int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight); + int nIndex = [&]() -> int { + if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) { + return GUIUtil::g_font_registry.WeightToIdx(weight); + } + return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightBoldDefault()); + }(); assert(nIndex != -1); return nIndex; }