diff options
author | Hannah Meeks <hmeeks4135@gmail.com> | 2022-07-20 13:33:26 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-07-20 22:45:18 +0200 |
commit | 4205fb723144e825ae75e977034a6df1a99f4881 (patch) | |
tree | fbabe1bba83e96be1113005b7df820556a2ff74b /sw/source | |
parent | f6d45f07fcbb33ce542f128caf90064a85a91d31 (diff) |
VBA Fix off by one error in setting range
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 <quikee@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/ui/vba/vbadocument.cxx | 30 |
1 files changed, 21 insertions, 9 deletions
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() ) |