From fc9684a130300e5655aedda34eefd8ddf0db0f92 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 30 Sep 2023 13:01:20 +0200 Subject: [PATCH] Prevent access to null local_font --- src/insets/Inset.cpp | 8 ++++++++ src/insets/Inset.h | 4 ++++ src/insets/InsetBox.cpp | 3 ++- src/insets/InsetFloatList.cpp | 6 +++--- src/insets/InsetIndex.cpp | 2 +- src/insets/InsetListings.cpp | 7 +++---- src/insets/InsetNomencl.cpp | 4 ++-- src/insets/InsetQuotes.cpp | 6 +++--- src/insets/InsetRef.cpp | 2 +- src/insets/InsetSpace.cpp | 3 +-- src/insets/InsetSpecialChar.cpp | 6 +++--- src/insets/InsetTabular.cpp | 6 ++++-- 12 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 6e89950f96..6e3bb67a9d 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -672,4 +672,12 @@ docstring Inset::completionPrefix(Cursor const &) const return docstring(); } + +Language const * Inset::getLocalOrDefaultLang(const OutputParams & rp) const +{ + return (rp.local_font != nullptr) + ? rp.local_font->language() + : buffer().params().language; +} + } // namespace lyx diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 1b7adb5e89..04fffe950b 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -54,6 +54,7 @@ class InsetList; class InsetMath; class InsetTabular; class InsetText; +class Language; class LaTeXFeatures; class Lexer; class MathAtom; @@ -618,6 +619,9 @@ public: /// Determine the action of backspace and delete: do we select instead of /// deleting if not already selected? virtual bool confirmDeletion() const { return false; } + /// Return the local_font's language or the buffer's default language + /// if local_font is null + Language const * getLocalOrDefaultLang(const OutputParams &) const; protected: /// Constructors diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 9ff8cea24d..36507cf8e2 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -355,7 +355,8 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const string maybeBeginL; string maybeEndL; bool needEndL = false; - if (!runparams.isFullUnicode() && runparams.local_font->isRightToLeft()) { + if (!runparams.isFullUnicode() + && runparams.local_font && runparams.local_font->isRightToLeft()) { maybeBeginL = "\\beginL"; maybeEndL = "\\endL"; } diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp index e711feebf4..3315d3b896 100644 --- a/src/insets/InsetFloatList.cpp +++ b/src/insets/InsetFloatList.cpp @@ -195,11 +195,11 @@ docstring InsetFloatList::xhtml(XMLStream &, OutputParams const & op) const { if (type == "table") { toctype = "table"; toclabel = translateIfPossible(from_ascii("List of Tables"), - op.local_font->language()->lang()); + getLocalOrDefaultLang(op)->lang()); } else if (type == "figure") { toctype = "figure"; toclabel = translateIfPossible(from_ascii("List of Figures"), - op.local_font->language()->lang()); + getLocalOrDefaultLang(op)->lang()); } else { LYXERR0("Unknown Builtin Float!"); return docstring(); @@ -207,7 +207,7 @@ docstring InsetFloatList::xhtml(XMLStream &, OutputParams const & op) const { } else { toctype = to_utf8(getParam("type")); toclabel = translateIfPossible(from_utf8(cit->second.listName()), - op.local_font->language()->lang()); + getLocalOrDefaultLang(op)->lang()); } shared_ptr toc = buffer().tocBackend().toc(toctype); diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index b20b553a78..67f932ed97 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -1911,7 +1911,7 @@ docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const xs << xml::StartTag("div", tocattr); xs << xml::CR(); xs << xml::StartTag(lay.htmltag(), lay.htmlGetAttrString()); - xs << translateIfPossible(indexName, op.local_font->language()->lang()); + xs << translateIfPossible(indexName, getLocalOrDefaultLang(op)->lang()); xs << xml::EndTag(lay.htmltag()); xs << xml::CR(); xs << xml::StartTag("ul", "class='main'"); diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index bd61986243..8268cebd68 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -187,7 +187,8 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const if (!basicstyle.empty()) param_string = rtrim(param_string, ",") + ",basicstyle={" + basicstyle + "}"; } - if (runparams.use_polyglossia && runparams.local_font->isRightToLeft()) { + if (runparams.use_polyglossia && runparams.local_font + && runparams.local_font->isRightToLeft()) { // We need to use the *latin switches (#11554) smatch sub; if (regex_match(param_string, sub, reg1)) @@ -248,9 +249,7 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const Encoding const * const save_enc = runparams.encoding; Encoding const * const outer_encoding = - (runparams.local_font != 0) ? - runparams.local_font->language()->encoding() - : buffer().params().language->encoding(); + getLocalOrDefaultLang(runparams)->encoding(); Encoding const * fixedlstenc = forcedEncoding(runparams.encoding, outer_encoding); if (fixedlstenc) { // We need to switch to a singlebyte encoding, due to diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 1d77826602..1d2ceb3318 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -222,7 +222,7 @@ docstring InsetPrintNomencl::xhtml(XMLStream &, OutputParams const & op) const InsetLayout const & il = getLayout(); string const & tag = il.htmltag(); docstring toclabel = translateIfPossible(from_ascii("Nomenclature"), - op.local_font->language()->lang()); + getLocalOrDefaultLang(op)->lang()); xs << xml::StartTag("div", "class='nomencl'") << xml::StartTag(tag, "class='nomencl'") @@ -333,7 +333,7 @@ void InsetPrintNomencl::docbook(XMLStream & xs, OutputParams const & runparams) // TODO: At least, that's what was done before... docstring toclabel = translateIfPossible(from_ascii("Nomenclature"), - runparams.local_font->language()->lang()); + getLocalOrDefaultLang(runparams)->lang()); xs << xml::StartTag("glossary"); xs << xml::CR(); diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index 53709daba4..46b8ef11ae 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -814,7 +814,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const || style == QuoteStyle::French || style == QuoteStyle::FrenchIN) && level_ == QuoteLevel::Primary - && prefixIs(runparams.local_font->language()->code(), "fr")) { + && prefixIs(getLocalOrDefaultLang(runparams)->code(), "fr")) { // Specific guillemets of French babel // including correct French spacing if (side_ == QuoteSide::Opening) @@ -826,11 +826,11 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const // (ligatures not featured in PDF strings) qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_); } else if (runparams.main_fontenc == "T1" - && !runparams.local_font->language()->internalFontEncoding()) { + && !getLocalOrDefaultLang(runparams)->internalFontEncoding()) { // Quotation marks for T1 font encoding // (using ligatures) qstr = quoteparams.getLaTeXQuote(quotechar, "t1"); - } else if (runparams.local_font->language()->internalFontEncoding()) { + } else if (getLocalOrDefaultLang(runparams)->internalFontEncoding()) { // Quotation marks for internal font encodings // (ligatures not featured) qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_); diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 746b9ea870..c8bc837a5f 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -432,7 +432,7 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const // some sort of counter with the label, and we don't have that yet. docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"'; xs << xml::StartTag("a", to_utf8(attr)); - xs << displayString(ref, cmd, op.local_font->language()->lang());; + xs << displayString(ref, cmd, getLocalOrDefaultLang(op)->lang()); xs << xml::EndTag("a"); return docstring(); } diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 0e0b9b6aac..53fda518da 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -588,8 +588,7 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const case InsetSpaceParams::PROTECTED: if (runparams.find_effective()) os.put(0xa0); - else if (runparams.local_font - && runparams.local_font->language()->lang() == "polutonikogreek") + else if (getLocalOrDefaultLang(runparams)->lang() == "polutonikogreek") // in babel's polutonikogreek, ~ is active os << (runparams.free_spacing ? " " : "\\nobreakspace{}"); else diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index f930ed7b67..a1f7fec332 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -421,15 +421,15 @@ void InsetSpecialChar::read(Lexer & lex) void InsetSpecialChar::latex(otexstream & os, OutputParams const & rp) const { - bool const rtl = rp.local_font->isRightToLeft(); + bool const rtl = rp.local_font && rp.local_font->isRightToLeft(); bool const utf8 = rp.encoding->iconvName() == "UTF-8"; string lswitch = ""; string lswitche = ""; if (rtl && !rp.use_polyglossia) { lswitch = "\\L{"; lswitche = "}"; - if (rp.local_font->language()->lang() == "arabic_arabi" - || rp.local_font->language()->lang() == "farsi") + if (getLocalOrDefaultLang(rp)->lang() == "arabic_arabi" + || getLocalOrDefaultLang(rp)->lang() == "farsi") lswitch = "\\textLR{"; } diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index e8fc1baf97..6572dfe52a 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3179,7 +3179,8 @@ void Tabular::TeXRow(otexstream & os, row_type row, // The bidi package (loaded by polyglossia with XeTeX) reverses RTL table columns // Luabibdi (used by LuaTeX) behaves like classic bool const bidi_rtl = - runparams.local_font->isRightToLeft() + runparams.local_font + && runparams.local_font->isRightToLeft() && buffer().params().useBidiPackage(runparams); bool const ct = !buffer().params().output_changes; idx_type lastcell = @@ -3351,7 +3352,8 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const // The bidi package (loaded by polyglossia with XeTeX) swaps the column // order for RTL (#9686). Thus we use this list. bool const bidi_rtl = - runparams.local_font->isRightToLeft() + runparams.local_font + && runparams.local_font->isRightToLeft() && buffer().params().useBidiPackage(runparams); list columns; list logical_columns; -- 2.39.5