From: Abdelrazak Younes Date: Tue, 17 Oct 2006 16:23:27 +0000 (+0000) Subject: This commit fixes a crash when accessing a math inset. This was due to an invalid... X-Git-Tag: 1.6.10~12365 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4cc7a7708e1753fc0ece02a9b8029ef1e9bd2921;p=lyx.git This commit fixes a crash when accessing a math inset. This was due to an invalid CursorSlice::text() null pointer accessed in InsetMathNest::cursorPos(): CoordCache & coord_cache = sl.text()->bv()->coordCache(); As you can see, I used this indirection to access the BufferView::CoordCache(). Bad luck, the passed CursorSlice was not completely valid inside a mathed inset, hence the crash. My solution is to pass BufferView to InsetBase::cursorPos() and all its derivative. * InsetBase::cursorPos(): pass BufferView const & * bufferview_funcs::coordOffset(): ditto. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15356 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index e5e1678da8..cc2afe0f32 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -608,7 +608,7 @@ void BufferView::center() bot.text()->redoParagraph(pit); Paragraph const & par = bot.text()->paragraphs()[pit]; anchor_ref_ = pit; - offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_ + offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_ + par.ascent() - height_ / 2; } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 1f0ff23106..508f40e277 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -156,7 +156,8 @@ bool string2font(string const & data, LyXFont & font, bool & toggle) // the next two should probably go elsewhere // this give the position relative to (0, baseline) of outermost // paragraph -Point coordOffset(DocIterator const & dit, bool boundary) +Point coordOffset(BufferView const & bv, DocIterator const & dit, + bool boundary) { int x = 0; int y = 0; @@ -166,7 +167,7 @@ Point coordOffset(DocIterator const & dit, bool boundary) CursorSlice const & sl = dit[i]; int xx = 0; int yy = 0; - sl.inset().cursorPos(sl, boundary && ((i+1) == dit.depth()), xx, yy); + sl.inset().cursorPos(bv, sl, boundary && ((i+1) == dit.depth()), xx, yy); x += xx; y += yy; //lyxerr << "LCursor::getPos, i: " @@ -215,7 +216,7 @@ Point getPos(BufferView & bv, DocIterator const & dit, bool boundary) //lyxerr << "cursor out of view" << std::endl; return Point(-1, -1); } - Point p = coordOffset(dit, boundary); // offset from outer paragraph + Point p = coordOffset(bv, dit, boundary); // offset from outer paragraph p.y_ += it->second.y_; return p; } diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index 66931166c4..e4026ce732 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -52,7 +52,7 @@ enum CurStatus { CurStatus status(BufferView const * bv, DocIterator const & dit); -lyx::Point coordOffset(DocIterator const & dit, bool boundary); +lyx::Point coordOffset(BufferView const & bv, DocIterator const & dit, bool boundary); /// Moves cursor to the next inset with one of the given codes. void gotoInset(BufferView * bv, std::vector const & codes, diff --git a/src/cursor.C b/src/cursor.C index 69ba63b195..2583ab12a8 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -101,7 +101,7 @@ namespace { int yo; InsetBase const * inset = &it.inset(); Point o = c.bv().coordCache().getInsets().xy(inset); - inset->cursorPos(it.top(), c.boundary(), xo, yo); + inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo); // Convert to absolute xo += o.x_; yo += o.y_; diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 6f5453a283..8fe2477d24 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -269,7 +269,8 @@ void InsetBase::markErased(bool) {} -void InsetBase::cursorPos(CursorSlice const &, bool, int & x, int & y) const +void InsetBase::cursorPos(BufferView const & bv, CursorSlice const &, + bool, int & x, int & y) const { lyxerr << "InsetBase::cursorPos called directly" << std::endl; x = 100; diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 05a797909e..3f99b98e6c 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -124,8 +124,8 @@ public: /// do we cover screen position x/y? virtual bool covers(BufferView & bv, int x, int y) const; /// get the screen positions of the cursor (see note in cursor.C) - virtual void cursorPos(CursorSlice const & sl, bool boundary, - int & x, int & y) const; + virtual void cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const; /// is this an inset that can be moved into? virtual bool isActive() const { return nargs() > 0; } diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 0638430c70..bf4c5c976e 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -81,10 +81,10 @@ docstring const InsetCaption::editMessage() const } -void InsetCaption::cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const +void InsetCaption::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { - InsetText::cursorPos(sl, boundary, x, y); + InsetText::cursorPos(bv, sl, boundary, x, y); x += labelwidth_; } diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 3b57d832c8..ab6d971155 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -35,8 +35,8 @@ public: /// virtual lyx::docstring const editMessage() const; /// - virtual void cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const; + virtual void cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const; /// bool descendable() const { return true; } /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 16b0d68f75..a8bf0856aa 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -211,12 +211,12 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const } -void InsetCollapsable::cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const +void InsetCollapsable::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { BOOST_ASSERT(status() != Collapsed); - InsetText::cursorPos(sl, boundary, x, y); + InsetText::cursorPos(bv, sl, boundary, x, y); if (status() == Open) { if (openinlined_) diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 880bfeacd9..41a826a51c 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -55,7 +55,8 @@ public: /// void drawSelection(PainterInfo & pi, int x, int y) const; /// return x,y of given position relative to the inset's baseline - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; /// bool hitButton(FuncRequest const &) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 0ac3d57731..df79c6718e 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1117,10 +1117,10 @@ shared_ptr InsetTabular::cell(idx_type idx) } -void InsetTabular::cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const +void InsetTabular::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { - cell(sl.idx())->cursorPos(sl, boundary, x, y); + cell(sl.idx())->cursorPos(bv, sl, boundary, x, y); // y offset correction int const row = tabular.row_of_cell(sl.idx()); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 2b77adc5a9..2c4505e147 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -97,7 +97,8 @@ public: /// Code lyxCode() const { return InsetBase::TABULAR_CODE; } /// get offset of this cursor slice relative to our upper left corner - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; /// bool tabularFeatures(LCursor & cur, std::string const & what); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 33c041ce42..a926f31538 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -301,8 +301,8 @@ void InsetText::validate(LaTeXFeatures & features) const } -void InsetText::cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const +void InsetText::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { x = text_.cursorX(sl, boundary) + border_; y = text_.cursorY(sl, boundary); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 23f054e93b..d7d93eedf8 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -73,7 +73,8 @@ public: void validate(LaTeXFeatures & features) const; /// return x,y of given position relative to the inset's baseline - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; /// Code lyxCode() const { return TEXT_CODE; } /// diff --git a/src/mathed/InsetMathMBox.C b/src/mathed/InsetMathMBox.C index 970ffc4a06..37ed78429d 100644 --- a/src/mathed/InsetMathMBox.C +++ b/src/mathed/InsetMathMBox.C @@ -102,8 +102,8 @@ LyXText * InsetMathMBox::getText(int) const } -void InsetMathMBox::cursorPos - (CursorSlice const & sl, bool boundary, int & x, int & y) const +void InsetMathMBox::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { x = text_.cursorX(sl, boundary); y = text_.cursorY(sl, boundary); diff --git a/src/mathed/InsetMathMBox.h b/src/mathed/InsetMathMBox.h index 39fa6e996a..305d88fd18 100644 --- a/src/mathed/InsetMathMBox.h +++ b/src/mathed/InsetMathMBox.h @@ -41,7 +41,8 @@ public: /// LyXText * getText(int) const; /// - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; protected: virtual void doDispatch(LCursor & cur, FuncRequest & cmd); diff --git a/src/mathed/InsetMathMacro.C b/src/mathed/InsetMathMacro.C index efad92485d..1bf8dadc39 100644 --- a/src/mathed/InsetMathMacro.C +++ b/src/mathed/InsetMathMacro.C @@ -48,12 +48,12 @@ string MathMacro::name() const } -void MathMacro::cursorPos(CursorSlice const & sl, bool boundary, int & x, - int & y) const +void MathMacro::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool boundary, int & x, int & y) const { // We may have 0 arguments, but InsetMathNest requires at least one. if (nargs() > 0) - InsetMathNest::cursorPos(sl, boundary, x, y); + InsetMathNest::cursorPos(bv, sl, boundary, x, y); } diff --git a/src/mathed/InsetMathMacro.h b/src/mathed/InsetMathMacro.h index 3c82d9ac24..02c097bfb2 100644 --- a/src/mathed/InsetMathMacro.h +++ b/src/mathed/InsetMathMacro.h @@ -33,7 +33,8 @@ public: /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// get cursor position - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; /// InsetBase * editXY(LCursor & cur, int x, int y); /// diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index e0e3e419a2..37db10add0 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -98,8 +98,9 @@ MathArray const & InsetMathNest::cell(idx_type i) const } -void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/, - int & x, int & y) const +void InsetMathNest::cursorPos(BufferView const & bv, + CursorSlice const & sl, bool /*boundary*/, + int & x, int & y) const { // FIXME: This is a hack. Ideally, the coord cache should not store // absolute positions, but relative ones. This would mean to call @@ -110,7 +111,7 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/, // absolute again when actually drawing the cursor. What a mess. BOOST_ASSERT(ptr_cmp(&sl.inset(), this)); MathArray const & ar = sl.cell(); - CoordCache & coord_cache = sl.text()->bv()->coordCache(); + CoordCache const & coord_cache = bv.coordCache(); if (!coord_cache.getArrays().has(&ar)) { // this can (semi-)legally happen if we just created this cell // and it never has been drawn before. So don't ASSERT. diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 7790be0872..74908c31cf 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -37,7 +37,8 @@ public: /// identifies NestInsets InsetMathNest const * asNestInset() const { return this; } /// get cursor position - void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const; + void cursorPos(BufferView const & bv, CursorSlice const & sl, + bool boundary, int & x, int & y) const; /// void edit(LCursor & cur, bool left); /// diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index 8b026fe434..a10b938351 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -15,6 +15,8 @@ #include "support/docstring.h" +#include + class PainterInfo; class LyXFont; class Dimension;