From 051181fa6ee00d8379e8a7dc7442b58342d4352b Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 9 Jul 2022 22:32:08 +0200 Subject: Enforce limits of settings that could cause buggy behaviour (#12450) Enforces the setting value bounds that are currently only limited by the GUI (settingtypes.txt). --- src/client/fontengine.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/client/fontengine.cpp') diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp index ad8305b45..0ae50dfe2 100644 --- a/src/client/fontengine.cpp +++ b/src/client/fontengine.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "gettext.h" #include "irrlicht_changes/CGUITTFont.h" +#include "util/numeric.h" // rangelim /** maximum size distance for getting a "similar" font size */ #define MAX_FONT_SIZE_OFFSET 10 @@ -172,9 +173,9 @@ unsigned int FontEngine::getFontSize(FontMode mode) /******************************************************************************/ void FontEngine::readSettings() { - m_default_size[FM_Standard] = g_settings->getU16("font_size"); - m_default_size[_FM_Fallback] = g_settings->getU16("font_size"); - m_default_size[FM_Mono] = g_settings->getU16("mono_font_size"); + m_default_size[FM_Standard] = rangelim(g_settings->getU16("font_size"), 5, 72); + m_default_size[_FM_Fallback] = m_default_size[FM_Standard]; + m_default_size[FM_Mono] = rangelim(g_settings->getU16("mono_font_size"), 5, 72); m_default_bold = g_settings->getBool("font_bold"); m_default_italic = g_settings->getBool("font_italic"); @@ -217,8 +218,9 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec) if (spec.italic) setting_suffix.append("_italic"); - u32 size = std::max(spec.size * RenderingEngine::getDisplayDensity() * - g_settings->getFloat("gui_scaling"), 1); + // Font size in pixels for FreeType + u32 size = rangelim(spec.size * RenderingEngine::getDisplayDensity() * + g_settings->getFloat("gui_scaling"), 1U, 500U); // Constrain the font size to a certain multiple, if necessary u16 divisible_by = g_settings->getU16(setting_prefix + "font_size_divisible_by"); -- cgit v1.2.3