From 75e7643e22bcf674739ca890bfc06f80e872624b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 10 May 2012 21:46:53 +0100 Subject: Related: fdo#47644 get out of bounds conditions right Change-Id: Icac9a8337296f92af5007a051f00388a64955178 --- sot/source/sdstor/stgstrms.cxx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx index 88bc41630f4b..3ee485e66432 100644 --- a/sot/source/sdstor/stgstrms.cxx +++ b/sot/source/sdstor/stgstrms.cxx @@ -455,17 +455,14 @@ sal_Bool StgStrm::Pos2Page( sal_Int32 nBytePos ) } else { - size_t nBgnDistance = std::distance(m_aPagesCache.begin(), aI); + size_t nBgnIndex = std::distance(m_aPagesCache.begin(), aI); + size_t nIndex = nBgnIndex + nRel; - size_t nIndex = nBgnDistance + nRel; - - if (nIndex > m_aPagesCache.size()) - { - nRel = m_aPagesCache.size() - nBgnDistance; + if (nIndex >= m_aPagesCache.size()) nIndex = m_aPagesCache.size() - 1; - } - else - nRel = 0; + + size_t nSuccessfulStepsTaken = nIndex - nBgnIndex; + nRel -= nSuccessfulStepsTaken; nLast = nIndex ? m_aPagesCache[nIndex - 1] : STG_EOF; nBgn = m_aPagesCache[nIndex]; -- cgit v1.2.3