aboutsummaryrefslogtreecommitdiff
path: root/src/client/fontengine.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-07-09 22:32:08 +0200
committerGitHub <noreply@github.com>2022-07-09 22:32:08 +0200
commit051181fa6ee00d8379e8a7dc7442b58342d4352b (patch)
tree58ad84f05310024b311c533684defdbeb5ee3e84 /src/client/fontengine.cpp
parent7c261118e06c630ea9ad00f20d7005b8edc108dd (diff)
downloadminetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.tar.gz
minetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.tar.bz2
minetest-051181fa6ee00d8379e8a7dc7442b58342d4352b.zip
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).
Diffstat (limited to 'src/client/fontengine.cpp')
-rw-r--r--src/client/fontengine.cpp12
1 files changed, 7 insertions, 5 deletions
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<u32>(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");