From dad0b78901b1ddb57949982c4099ea641749bfb2 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 12 Oct 2018 19:41:34 +0400 Subject: [PATCH] Avoid overflow when handling output characters (bug #4676) --- apps/openmw/mwgui/bookpage.cpp | 8 ++++---- apps/openmw/mwgui/bookpage.hpp | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/bookpage.cpp b/apps/openmw/mwgui/bookpage.cpp index 29dfe7f3a6..80e92f15ae 100644 --- a/apps/openmw/mwgui/bookpage.cpp +++ b/apps/openmw/mwgui/bookpage.cpp @@ -506,7 +506,7 @@ struct TypesetBookImpl::Typesetter : BookTypesetter while (!stream.eof () && !ucsLineBreak (stream.peek ()) && ucsBreakingSpace (stream.peek ())) { MWGui::GlyphInfo info = GlyphInfo(style->mFont, stream.peek()); - if (info.codePoint >= 0) + if (info.charFound) space_width += static_cast(info.advance + info.bearingX); stream.consume (); } @@ -516,7 +516,7 @@ struct TypesetBookImpl::Typesetter : BookTypesetter while (!stream.eof () && !ucsLineBreak (stream.peek ()) && !ucsBreakingSpace (stream.peek ())) { MWGui::GlyphInfo info = GlyphInfo(style->mFont, stream.peek()); - if (info.codePoint >= 0) + if (info.charFound) word_width += static_cast(info.advance + info.bearingX); stream.consume (); } @@ -765,7 +765,7 @@ namespace { MWGui::GlyphInfo info = GlyphInfo(mFont, ch); - if (info.codePoint < 0) + if (!info.charFound) return; MyGUI::FloatRect vr; @@ -787,7 +787,7 @@ namespace { MWGui::GlyphInfo info = GlyphInfo(mFont, ch); - if (info.codePoint >= 0) + if (info.charFound) mCursor.left += static_cast(info.bearingX + info.advance); } diff --git a/apps/openmw/mwgui/bookpage.hpp b/apps/openmw/mwgui/bookpage.hpp index 4cf99794d7..4ea59414df 100644 --- a/apps/openmw/mwgui/bookpage.hpp +++ b/apps/openmw/mwgui/bookpage.hpp @@ -43,6 +43,7 @@ namespace MWGui float advance; float bearingX; float bearingY; + bool charFound; MyGUI::FloatRect uvRect; GlyphInfo(MyGUI::IFont* font, MyGUI::Char ch) @@ -61,15 +62,17 @@ namespace MWGui height = (int) gi->height / scale; advance = (int) gi->advance / scale; uvRect = gi->uvRect; + charFound = true; } else { - codePoint = -1; + codePoint = 0; bearingX = 0; bearingY = 0; width = 0; height = 0; advance = 0; + charFound = false; } } };