From 4205fb723144e825ae75e977034a6df1a99f4881 Mon Sep 17 00:00:00 2001 From: Hannah Meeks Date: Wed, 20 Jul 2022 13:33:26 +0100 Subject: VBA Fix off by one error in setting range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xEnd should not be smaller than xStart for compatibility Add first Document tests Change-Id: Ia8898d79db8c2885c6253ee9aaca793082b9dd20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137262 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sw/source/ui/vba/vbadocument.cxx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'sw/source') diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index 4a1a8dd8a2ae..79faf58fe4ab 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -137,22 +137,34 @@ SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd ) sal_Int32 nEnd = 0; rStart >>= nStart; rEnd >>= nEnd; - nStart--; - nEnd--; uno::Reference< text::XTextRange > xStart; uno::Reference< text::XTextRange > xEnd; - if( nStart != -1 || nEnd != -1 ) - { - if( nStart == -1 ) - xStart = mxTextDocument->getText()->getStart(); - else - xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart ); - if( nEnd == -1 ) + if( nStart > nEnd) + throw uno::RuntimeException(); + + if( nEnd != 0) + { + if( nEnd == nStart ) + { + xStart = mxTextDocument->getText()->getEnd(); xEnd = mxTextDocument->getText()->getEnd(); + } else + { xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd ); + + if( nStart != 0 ) + xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart ); + else + xStart = mxTextDocument->getText()->getStart(); + } + } + else + { + xStart = mxTextDocument->getText()->getEnd(); + xEnd = mxTextDocument->getText()->getEnd(); } if( !xStart.is() && !xEnd.is() ) -- cgit