]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Make sure a pointer is valid before using it
[lyx.git] / src / lyxfind.cpp
index 2cd05ea4a75759a89c052c8c697d1099223d9479..cc8d1cf12ff07abb9c6b74cf476a117862e6ecc5 100644 (file)
@@ -385,7 +385,6 @@ bool lyxreplace(BufferView * bv,
                else
                        bv->message(_("String not found."));
        }
-       bv->buffer().updatePreviews();
        return update;
 }
 
@@ -728,9 +727,8 @@ private:
 static docstring buffer_to_latex(Buffer & buffer)
 {
        OutputParams runparams(&buffer.params().encoding());
-       TexRow texrow(false);
        odocstringstream ods;
-       otexstream os(ods, texrow);
+       otexstream os(ods, false);
        runparams.nice = true;
        runparams.flavor = OutputParams::LATEX;
        runparams.linelen = 80; //lyxrc.plaintext_linelen;
@@ -1008,7 +1006,6 @@ docstring stringifyFromCursor(DocIterator const & cur, int len)
                pos_type end = ( len == -1 || cur.pos() + len > int(par.size()) ) ?
                        int(par.size()) : cur.pos() + len;
                OutputParams runparams(&cur.buffer()->params().encoding());
-               odocstringstream os;
                runparams.nice = true;
                runparams.flavor = OutputParams::LATEX;
                runparams.linelen = 100000; //lyxrc.plaintext_linelen;
@@ -1050,9 +1047,8 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
        Buffer const & buf = *cur.buffer();
        LBUFERR(buf.params().isLatex());
 
-       TexRow texrow(false);
        odocstringstream ods;
-       otexstream os(ods, texrow);
+       otexstream os(ods, false);
        OutputParams runparams(&buf.params().encoding());
        runparams.nice = false;
        runparams.flavor = OutputParams::LATEX;
@@ -1072,8 +1068,8 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly
                for (int s = cur.depth() - 1; s >= 0; --s) {
                        CursorSlice const & cs = cur[s];
-                       if (cs.asInsetMath() && cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
-                               WriteStream ws(ods);
+                       if (cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
+                               WriteStream ws(os);
                                cs.asInsetMath()->asHullInset()->header_write(ws);
                                break;
                        }
@@ -1095,7 +1091,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                        CursorSlice const & cs = cur[s];
                        InsetMath * inset = cs.asInsetMath();
                        if (inset && inset->asHullInset()) {
-                               WriteStream ws(ods);
+                               WriteStream ws(os);
                                inset->asHullInset()->footer_write(ws);
                                break;
                        }
@@ -1397,9 +1393,8 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
                sel_len = repl_buffer.paragraphs().begin()->size();
        } else if (cur.inMathed()) {
-               TexRow texrow(false);
                odocstringstream ods;
-               otexstream os(ods, texrow);
+               otexstream os(ods, false);
                OutputParams runparams(&repl_buffer.params().encoding());
                runparams.nice = false;
                runparams.flavor = OutputParams::LATEX;
@@ -1410,6 +1405,8 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                docstring repl_latex = ods.str();
                LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'");
                string s;
+               // false positive from coverity
+               // coverity[CHECKED_RETURN]
                regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1");
                regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1");
                repl_latex = from_utf8(s);
@@ -1427,7 +1424,6 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
        LYXERR(Debug::FIND, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len);
        bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward);
        bv->processUpdateFlags(Update::Force);
-       bv->buffer().updatePreviews();
 }