From 4fcbb93e39800f6188a0bb70183f18fc7438ce17 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Wed, 23 Mar 2011 17:43:13 +0000 Subject: [PATCH] Do not give access to the actual data of the CoordCache. This prevents the use of the stored pointers which might be invalid. See also r38011. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38012 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CoordCache.cpp | 4 ++-- src/CoordCache.h | 3 --- src/Cursor.cpp | 8 +++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/CoordCache.cpp b/src/CoordCache.cpp index 515c0bb5c7..d1d41e3968 100644 --- a/src/CoordCache.cpp +++ b/src/CoordCache.cpp @@ -52,8 +52,8 @@ void CoordCache::dump() const { LYXERR0("InsetCache contains:"); CoordCacheBase::cache_type::const_iterator it = - getInsets().getData().begin(); - for (; it != getInsets().getData().end(); ++it) { + getInsets().data_.begin(); + for (; it != getInsets().data_.end(); ++it) { // Warning: it is not guaranteed that inset is a valid pointer // (therefore it has type 'void *') (see bug #7376). void const * inset = it->first; diff --git a/src/CoordCache.h b/src/CoordCache.h index 0f876be44e..99d31a9280 100644 --- a/src/CoordCache.h +++ b/src/CoordCache.h @@ -161,9 +161,6 @@ private: typedef std::map cache_type; cache_type data_; - -public: - cache_type const & getData() const { return data_; } }; /** diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 6144d5c28e..22b75b5a26 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -95,20 +95,18 @@ DocIterator bruteFind2(Cursor const & c, int x, int y) int xo; int yo; Inset const * inset = &it.inset(); - map const & data = - c.bv().coordCache().getInsets().getData(); - map::const_iterator I = data.find(inset); + CoordCache const & cache = c.bv().coordCache(); // FIXME: in the case where the inset is not in the cache, this // means that no part of it is visible on screen. In this case // we don't do elaborate search and we just return the forwarded // DocIterator at its beginning. - if (I == data.end()) { + if (!cache.getInsets().has(inset)) { it.top().pos() = 0; return it; } - Point o = I->second.pos; + Point const o = cache.getInsets().xy(inset); inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo); // Convert to absolute xo += o.x_;