[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - vcl/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 12 10:32:02 UTC 2020


 vcl/source/control/edit.cxx |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

New commits:
commit 6aee963e87836eceee4c65ab55aa8e8e270d7559
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Feb 11 10:31:18 2020 +0100
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Wed Feb 12 11:31:29 2020 +0100

    tdf#130555: Prevent negative aSelection.Min()
    
    ...which would violate the the preconditions of the later call to maText.remove.
    
    When BreakIteratorImpl::previousWord
    (i18npool/source/breakiterator/breakiteratorImpl.cxx) is called to e.g. move
    back over a single space at the start of the text, at least for an en-US locale
    it will fall through to the call to BreakIterator_Unicode::previousWord
    (i18npool/source/breakiterator/breakiterator_unicode.cxx) at the bottom of the
    function.  That in turn calls icu::BreakIterator::preceding, which is documented
    (workdir/UnpackedTarball/icu/source/common/unicode/brkiter.h) to return
    icu::BreakIterator::DONE (i.e., -1, see
    workdir/UnpackedTarball/icu/source/common/unicode/brkiter.h) in that case, which
    causes BreakIterator_Unicode::previousWord to return a Boundary with startPos ==
    endPos == -1.
    
    The documentation of UNO method css.i18n.XBreakIterator::previousWord
    (offapi/com/sun/star/i18n/XBreakIterator.idl) is silent about the expected
    return value in such a case.  But lets assume that returning such a [-1..-1]
    Boundary is as intended, and locally address this case in Edit::ImplDelete,
    making aSelection start at the start of the text.
    
    Change-Id: I40e17ba602088e72aa6962cb41dd8e1cdf6e2561
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88431
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <erack at redhat.com>
    (cherry picked from commit e8f26dc13b65b1a05d948d9c95110c86315e8f20)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88403
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index d38d85a986c1..8ef8778ee132 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -68,6 +68,7 @@
 
 #include <officecfg/Office/Common.hxx>
 
+#include <algorithm>
 #include <memory>
 
 using namespace ::com::sun::star;
@@ -697,10 +698,14 @@ void Edit::ImplDelete( const Selection& rSelection, sal_uInt8 nDirection, sal_uI
             {
                 i18n::Boundary aBoundary = xBI->getWordBoundary( maText.toString(), aSelection.Min(),
                         GetSettings().GetLanguageTag().getLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES, true );
-                if ( aBoundary.startPos == aSelection.Min() )
+                auto startPos = aBoundary.startPos;
+                if ( startPos == aSelection.Min() )
+                {
                     aBoundary = xBI->previousWord( maText.toString(), aSelection.Min(),
                             GetSettings().GetLanguageTag().getLocale(), i18n::WordType::ANYWORD_IGNOREWHITESPACES );
-                aSelection.Min() = aBoundary.startPos;
+                    startPos = std::max(aBoundary.startPos, sal_Int32(0));
+                }
+                aSelection.Min() = startPos;
             }
             else if ( nMode == EDIT_DELMODE_RESTOFCONTENT )
                {


More information about the Libreoffice-commits mailing list