From 241a0119ef8468a78e78645ba0434455aacb4a9e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 10 Oct 2022 21:12:49 +0200 Subject: [PATCH] Fixed a crash in the Font::wrapText function. --- es-core/src/resources/Font.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index a4de6521f..28cfb1fef 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -347,21 +347,22 @@ std::string Font::wrapText(const std::string& text, } if (addDots) { - if (wrappedText.back() == ' ') { + if (!wrappedText.empty() && wrappedText.back() == ' ') { lineWidth -= sizeText(" ").x; wrappedText.pop_back(); } - else if (wrappedText.back() == '\t') { + else if (!wrappedText.empty() && wrappedText.back() == '\t') { lineWidth -= sizeText("\t").x; wrappedText.pop_back(); } - while (!dotsSection.empty() && lineWidth + dotsWidth > maxLength) { + while (!wrappedText.empty() && !dotsSection.empty() && lineWidth + dotsWidth > maxLength) { lineWidth -= dotsSection.back().second; wrappedText.erase(wrappedText.length() - dotsSection.back().first); dotsSection.pop_back(); } if (!wrappedText.empty() && wrappedText.back() == ' ') wrappedText.pop_back(); + wrappedText.append("..."); }