From e86f049b0bfede337c875e5f62d27186fcace37f Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 25 Jul 2017 21:20:10 +0200 Subject: sw: fix string accesses in SwScanner::NextWord() (related: tdf#109081) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getWordBoundary() can return bounds that do not include the starting nPos, if there are ZWSP characters at the starting position. This happens in the bugdoc of tdf#109081 where paragraph starts with 3 ZWSP and then 5 dashes, SwScanner is created from 0 to 1 and bounds are 3 to 8. Change-Id: I5fc41b98568a7211fc7d5f29bb87840371a4c005 (cherry picked from commit af78fa5f0d3d891b9a30e927a3b35c55f03a03a7) Reviewed-on: https://gerrit.libreoffice.org/40502 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sw/source/core/txtnode/txtedt.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sw') diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index e0c41585bf50..06e4ead70d8b 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -941,8 +941,16 @@ bool SwScanner::NextWord() { aBound.startPos = std::max( aBound.startPos, nStartPos ); aBound.endPos = std::min( aBound.endPos, nEndPos ); - nBegin = aBound.startPos; - nLen = aBound.endPos - nBegin; + if (aBound.endPos < aBound.startPos) + { + nBegin = nEndPos; + nLen = 0; // found word is outside of search interval + } + else + { + nBegin = aBound.startPos; + nLen = aBound.endPos - nBegin; + } } if( ! nLen ) -- cgit v1.2.3