]> git.lyx.org Git - lyx.git/commitdiff
Return false on invalid input in Font::fromString()
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 9 Jun 2024 06:09:01 +0000 (08:09 +0200)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 9 Jun 2024 17:10:05 +0000 (13:10 -0400)
Fixes crash with invalid font-update lfun

(cherry picked from commit 2a9648fc4c58a007f7ddb4012d608666f8cc2ec8)

src/Font.cpp
src/Text.cpp

index 7e0798d8ac59b123182b0b609b351d561c5f6db5..92308fd1d859e56edef8f98a4651073da8b1e594 100644 (file)
@@ -695,18 +695,26 @@ bool Font::fromString(string const & data, bool & toggle)
 
                if (token == "family") {
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        bits_.setFamily(FontFamily(next));
 
                } else if (token == "series") {
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        bits_.setSeries(FontSeries(next));
 
                } else if (token == "shape") {
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        bits_.setShape(FontShape(next));
 
                } else if (token == "size") {
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        bits_.setSize(FontSize(next));
                // FIXME: shall style be handled there? Probably not.
                } else if (token == "emph" || token == "underbar"
@@ -716,6 +724,8 @@ bool Font::fromString(string const & data, bool & toggle)
                        || token == "nospellcheck") {
 
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        FontState const misc = FontState(next);
 
                        if (token == "emph")
@@ -739,6 +749,8 @@ bool Font::fromString(string const & data, bool & toggle)
 
                } else if (token == "color") {
                        int const next = lex.getInteger();
+                       if (next == -1)
+                               return false;
                        bits_.setColor(ColorCode(next));
 
                /**
index 8e9b7a8313978cad987b1eb8d41d0e22568791b5..e94cedbd8102afee8b7f3ab09dc9aad8956633ba 100644 (file)
@@ -5988,7 +5988,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        toggleAndShow(cur, this, font, toggleall);
                        cur.message(bformat(_("Text properties applied: %1$s"), props));
                } else
-                       LYXERR0("Invalid argument of textstyle-update");
+                       cur.message(_("Invalid argument of textstyle-update"));
                break;
        }