]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Avoid null pointer dereference
[lyx.git] / src / Paragraph.cpp
index 369bda0d7e80e39e4cc47dc55276a3309071618d..3a4c3994268ca52960399211221887da33a5e75d 100644 (file)
@@ -1535,9 +1535,9 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
                        else if (features.runparams().main_fontenc != "T1"
                                 || ((&owner_->getFontSettings(bp, i))->language()->internalFontEncoding()))
                                features.require("textquotedbl");
-               } else if (ci.textfeature() && contains(ci.textpreamble(), '=')) {
+               } else if (ci.textFeature() && contains(ci.textPreamble(), '=')) {
                        // features that depend on the font or input encoding
-                       string feats = ci.textpreamble();
+                       string feats = ci.textPreamble();
                        string fontenc = (&owner_->getFontSettings(bp, i))->language()->fontenc(bp);
                        if (fontenc.empty())
                                fontenc = features.runparams().main_fontenc;
@@ -2539,10 +2539,10 @@ void Paragraph::latex(BufferParams const & bparams,
        pos_type body_pos = beginOfBody();
        unsigned int column = 0;
 
-       // If we are inside an non inheritFont() inset, the real outerfont is local_font
-       Font const real_outerfont = (!inInset().inheritFont()
-                                    && runparams.local_font != nullptr)
-                       ? Font(runparams.local_font->fontInfo()) : outerfont;
+       // If we are inside an non inheritFont() inset,
+       // the outerfont is the buffer's main font
+       Font const real_outerfont =
+               inInset().inheritFont() ? outerfont : Font(bparams.getFont());
 
        if (body_pos > 0) {
                // the optional argument is kept in curly brackets in
@@ -2788,12 +2788,12 @@ void Paragraph::latex(BufferParams const & bparams,
                                column += Changes::latexMarkChange(os, bparams,
                                        Change(Change::UNCHANGED), Change(Change::DELETED), rp);
                        }
-                       open_font = false;
                        // Has the language been closed in the latexWriteEndChanges() call above?
                        langClosed = running_font.language() != basefont.language()
                                        && running_font.language() != nextfont.language()
                                        && (running_font.language()->encoding()->package() != Encoding::CJK);
                        running_font = basefont;
+                       open_font &= !langClosed;
                }
 
                // if necessary, close language environment before opening CJK
@@ -2806,7 +2806,8 @@ void Paragraph::latex(BufferParams const & bparams,
                        string end_tag = subst(lang_end_command, "$$lang", running_lang);
                        os << from_ascii(end_tag);
                        column += end_tag.length();
-                       popLanguageName();
+                       if (!languageStackEmpty())
+                               popLanguageName();
                }
 
                // Switch file encoding if necessary (and allowed)
@@ -2894,7 +2895,7 @@ void Paragraph::latex(BufferParams const & bparams,
                                }
                        } else {
                                running_font = current_font;
-                               open_font = !langClosed;
+                               open_font &= !langClosed;
                        }
                }
 
@@ -4120,17 +4121,6 @@ bool Paragraph::needsCProtection(bool const fragile) const
                        continue;
                if (ins->needsCProtection(maintext, fragile))
                        return true;
-               // Now check math environments
-               InsetMath const * im = ins->asInsetMath();
-               if (!im || im->cell(0).empty())
-                       continue;
-               switch(im->cell(0)[0]->lyxCode()) {
-               case MATH_ENV_CODE:
-                       // these need cprotection
-                       return true;
-               default:
-                       break;
-               }
        }
 
        return false;