[LyX/master] Do not crash with uncodable character in math preview snippert (part of #11855)

Juergen Spitzmueller spitz at lyx.org
Thu Dec 1 14:07:03 UTC 2022


commit e500dc19c153341fa9d60f3b6dd5b4fddc165607
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Dec 1 16:01:38 2022 +0100

    Do not crash with uncodable character in math preview snippert (part of #11855)
---
 src/mathed/InsetMathHull.cpp |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 0ab06d2..f5dce80 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -709,7 +709,20 @@ static docstring latexString(InsetMathHull const & inset)
 	otexrowstream ots(ls);
 	TeXMathStream wi(ots, false, true, TeXMathStream::wsPreview, encoding);
 	inset.write(wi);
-	return ls.str();
+	docstring const s = ls.str();
+	docstring res;
+	for (char_type c : s) {
+	    if (encoding->encodable(c))
+		    res += c;
+	    else {
+		    // indicate the encoding error by a boxed '?'
+		    res += "{\\fboxsep=1pt\\fbox{?}}";
+		    LYXERR0("Uncodable character" << " '"
+			    << c
+			    << "'");
+	    }
+	}
+	return res;
 }
 
 


More information about the lyx-cvs mailing list