include/svtools/editbrowsebox.hxx |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 59a1402455bd03a9839df9133306974a354b6367
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Sep 18 14:29:29 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Sep 19 12:10:38 2023 +0200

    tdf#157304 Use normalized selection indices as string indices
    
    The start index of the selection can be larger than the
    end index.
    Take that into account when using these indices to
    calculate the index and character count to copy
    the relevant substring using `OUString::copy`.
    
    Without this, running the tdf#157304 macro would trigger
    an assert due to invalid indices being used.
    
    Backtrace:
    
        soffice.bin: .../libreoffice/sal/rtl/strtmpl.hxx:890: void 
rtl::str::newfromsubstring(rtl_tstring**, const rtl_tstring*, sal_int32, 
sal_int32) [with rtl_tstring = _rtl_ustring; sal_int32 = int]: assertion 
`false' failed.
    
        Thread 1 "soffice.bin" received signal SIGABRT, Aborted.
        __pthread_kill_implementation (threadid=<optimized out>, 
signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
        44      ./nptl/pthread_kill.c: No such file or directory.
        (gdb) bt
        #0  __pthread_kill_implementation (threadid=<optimized out>, 
signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
        #1  0x00007ffff78a814f in __pthread_kill_internal (signo=6, 
threadid=<optimized out>) at ./nptl/pthread_kill.c:78
        #2  0x00007ffff785a462 in __GI_raise (sig=sig@entry=6) at 
../sysdeps/posix/raise.c:26
        #3  0x00007ffff78444b2 in __GI_abort () at ./stdlib/abort.c:79
        #4  0x00007ffff78443d5 in __assert_fail_base
            (fmt=0x7ffff79b8dc8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
assertion=assertion@entry=0x7ffff7f6f2ec "false", 
file=file@entry=0x7ffff7f6be70 ".../libreoffice/sal/rtl/strtmpl.hxx", 
line=line@entry=890, function=function@entry=0x7ffff7f6f260 "void 
rtl::str::newFromSubString(rtl_tString**, const rtl_tString*, sal_Int32, 
sal_Int32) [with rtl_tString = _rtl_uString; sal_Int32 = int]") at 
./assert/assert.c:92
        #5  0x00007ffff78533a2 in __assert_fail
            (assertion=0x7ffff7f6f2ec "false", file=0x7ffff7f6be70 
".../libreoffice/sal/rtl/strtmpl.hxx", line=890, function=0x7ffff7f6f260 "void 
rtl::str::newFromSubString(rtl_tString**, const rtl_tString*, sal_Int32, 
sal_Int32) [with rtl_tString = _rtl_uString; sal_Int32 = int]") at 
./assert/assert.c:101
        #6  0x00007ffff7eee8b7 in 
rtl::str::newFromSubString<_rtl_uString>(_rtl_uString**, _rtl_uString const*, 
int, int) (ppThis=0x7fffffffae40, pFrom=0x55555e7af450, beginIndex=6, count=-6)
            at .../libreoffice/sal/rtl/strtmpl.hxx:890
        #7  0x00007ffff7ee91ca in rtl_uString_newFromSubString(rtl_uString**, 
rtl_uString const*, sal_Int32, sal_Int32) (ppThis=0x7fffffffae40, 
pFrom=0x55555e7af450, beginIndex=6, count=-6)
            at .../libreoffice/sal/rtl/ustring.cxx:1219
        #8  0x00007ffff1697b52 in rtl::OUString::copy(int, int) const 
(this=0x7fffffffae88, beginIndex=6, count=-6) at 
.../libreoffice/include/rtl/ustring.hxx:2229
        #9  0x00007ffff1814180 in 
svt::EntryImplementation::GetSelected(LineEnd) const (this=0x55555ed5e660) at 
.../libreoffice/include/svtools/editbrowsebox.hxx:371
        #10 0x00007ffff180d61b in FmXEditCell::getSelectedText() 
(this=0x55555ed5d500) at .../libreoffice/svx/source/fmcomp/gridcell.cxx:3739
        #11 0x00007fffdc1496f5 in gcc3::callVirtualMethod(void*, unsigned int, 
void*, _typelib_TypeDescriptionReference*, bool, unsigned long*, unsigned int, 
unsigned long*, double*)
            (pThis=0x55555ed5d600, nVtableIndex=8, 
pRegisterReturn=0x7fffffffb2f0, pReturnTypeRef=0x555555743db0, 
bSimpleReturn=false, pStack=0x7fffffffb020, nStack=0, pGPR=0x7fffffffb180, 
pFPR=0x7fffffffb1b0)
            at 
.../libreoffice/bridges/source/cpp_uno/gcc3_linux_x86-64/callvirtualmethod.cxx:75
        #12 0x00007fffdc1481a0 in 
cpp_call(bridges::cpp_uno::shared::UnoInterfaceProxy*, 
bridges::cpp_uno::shared::VtableSlot, typelib_TypeDescriptionReference*, 
sal_Int32, typelib_MethodParameter*, void*, void**, uno_Any**)
            (pThis=0x55555e7b0490, aVtableSlot=..., 
pReturnTypeRef=0x555555743db0, nParams=0, pParams=0x0, 
pUnoReturn=0x7fffffffb2f0, pUnoArgs=0x7fffffffb2e0, ppUnoExc=0x7fffffffb3d0)
            at 
.../libreoffice/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx:233
        #13 0x00007fffdc148cdd in 
bridges::cpp_uno::shared::unoInterfaceProxyDispatch(uno_Interface*, 
typelib_TypeDescription const*, void*, void**, uno_Any**)
            (pUnoI=0x55555e7b0490, pMemberDescr=0x55555cccccc0, 
pReturn=0x7fffffffb2f0, pArgs=0x7fffffffb2e0, ppException=0x7fffffffb3d0) at 
.../libreoffice/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx:413
        #14 0x00007fff5beb45f2 in stoc_corefl::(anonymous 
namespace)::IdlInterfaceMethodImpl::invoke(com::sun::star::uno::Any const&, 
com::sun::star::uno::Sequence<com::sun::star::uno::Any>&)
            (this=0x55555ed792f0, rObj=uno::Any("com.sun.star.uno.XInterface": 
...), rArgs=empty uno::Sequence) at 
.../libreoffice/stoc/source/corereflection/criface.cxx:590
        #15 0x00007fff68020606 in (anonymous 
namespace)::IntrospectionAccessStatic_Impl::getPropertyValueByIndex(com::sun::star::uno::Any
 const&, sal_Int32) const
            (this=0x55555cc55910, obj=uno::Any("com.sun.star.uno.XInterface": 
...), nSequenceIndex=13) at 
.../libreoffice/stoc/source/inspect/introspection.cxx:588
        #16 0x00007fff68020161 in (anonymous 
namespace)::IntrospectionAccessStatic_Impl::getPropertyValue(com::sun::star::uno::Any
 const&, rtl::OUString const&) const
            (this=0x55555cc55910, obj=uno::Any("com.sun.star.uno.XInterface": 
...), aPropertyName="SelectedText") at 
.../libreoffice/stoc/source/inspect/introspection.cxx:498
        #17 0x00007fff68022522 in (anonymous 
namespace)::ImplIntrospectionAccess::getPropertyValue(rtl::OUString const&) 
(this=0x55555f4211a0, aPropertyName="SelectedText")
            at .../libreoffice/stoc/source/inspect/introspection.cxx:1014
        #18 0x00007ffff4edb132 in SbUnoObject::Notify(SfxBroadcaster&, SfxHint 
const&) (this=0x55555e7b0530, rBC=..., rHint=...) at 
.../libreoffice/basic/source/classes/sbunoobj.cxx:2059
        #19 0x00007ffff39c55f6 in SfxBroadcaster::Broadcast(SfxHint const&) 
(this=0x55555e7b07d0, rHint=...) at 
.../libreoffice/svl/source/notify/SfxBroadcaster.cxx:40
        #20 0x00007ffff505a52b in SbxVariable::Broadcast(SfxHintId) 
(this=0x55555e7b09d0, nHintId=SfxHintId::BasicDataWanted) at 
.../libreoffice/basic/source/sbx/sbxvar.cxx:155
        #21 0x00007ffff5054564 in SbxValue::Get(SbxValues&) const 
(this=0x55555e7b09d0, rRes=...) at 
.../libreoffice/basic/source/sbx/sbxvalue.cxx:289
        #22 0x00007ffff50568fe in SbxValue::Compute(SbxOperator, SbxValue 
const&) (this=0x55555f441ac0, eOp=SbxCAT, rOp=...) at 
.../libreoffice/basic/source/sbx/sbxvalue.cxx:809
        #23 0x00007ffff4fd4fb9 in SbiRuntime::StepArith(SbxOperator) 
(this=0x55555f43f5d0, eOp=SbxCAT) at 
.../libreoffice/basic/source/runtime/runtime.cxx:1305
        #24 0x00007ffff4fd580d in SbiRuntime::StepCAT() (this=0x55555f43f5d0) 
at .../libreoffice/basic/source/runtime/runtime.cxx:1418
        #25 0x00007ffff4fd2fb8 in SbiRuntime::Step() (this=0x55555f43f5d0) at 
.../libreoffice/basic/source/runtime/runtime.cxx:795
        #26 0x00007ffff4f1c85f in (anonymous namespace)::RunInitGuard::run() 
(this=0x7fffffffbb40) at .../libreoffice/basic/source/classes/sbxmod.cxx:1017
        #27 0x00007ffff4f1d2f5 in SbModule::Run(SbMethod*) 
(this=0x55555cc779e0, pMeth=0x55555f435130) at 
.../libreoffice/basic/source/classes/sbxmod.cxx:1177
        #28 0x00007ffff4f1b907 in SbModule::Notify(SfxBroadcaster&, SfxHint 
const&) (this=0x55555cc779e0, rBC=..., rHint=...) at 
.../libreoffice/basic/source/classes/sbxmod.cxx:775
        #29 0x00007ffff39c55f6 in SfxBroadcaster::Broadcast(SfxHint const&) 
(this=0x55555f4305d0, rHint=...) at 
.../libreoffice/svl/source/notify/SfxBroadcaster.cxx:40
        #30 0x00007ffff4f221e4 in SbMethod::Broadcast(SfxHintId) 
(this=0x55555f430500, nHintId=SfxHintId::BasicDataWanted) at 
.../libreoffice/basic/source/classes/sbxmod.cxx:2121
        #31 0x00007ffff5054564 in SbxValue::Get(SbxValues&) const 
(this=0x55555f430500, rRes=...) at 
.../libreoffice/basic/source/sbx/sbxvalue.cxx:289
        #32 0x00007ffff4f21e88 in SbMethod::Call(SbxValue*, SbxVariable*) 
(this=0x55555f430500, pRet=0x55555f42fff0, pCaller=0x55555f441b60) at 
.../libreoffice/basic/source/classes/sbxmod.cxx:2077
        #33 0x00007fff60031152 in 
basprov::BasicScriptImpl::invoke(com::sun::star::uno::Sequence<com::sun::star::uno::Any>
 const&, com::sun::star::uno::Sequence<short>&, 
com::sun::star::uno::Sequence<com::sun::star::uno::Any>&)
            (this=0x55555eddeae0, aParams=uno::Sequence of length 1 = {...}, 
aOutParamIndex=empty uno::Sequence, aOutParam=empty uno::Sequence) at 
.../libreoffice/scripting/source/basprov/basscript.cxx:252
        #34 0x00007ffff440c3e8 in 
SfxObjectShell::CallXScript(com::sun::star::uno::Reference<com::sun::star::uno::XInterface>
 const&, rtl::OUString const&, 
com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&, 
com::sun::star::uno::Any&, com::sun::star::uno::Sequence<short>&, 
com::sun::star::uno::Sequence<com::sun::star::uno::Any>&, bool, 
com::sun::star::uno::Any const*)
            (_rxScriptContext=uno::Reference to (SwXTextDocument *) 
0x55555c8acf20, 
_rScriptURL="vnd.sun.star.script:Standard.Module1.TestFocus?language=Basic&location=document",
 aParams=uno::Sequence of length 1 = {...}, aRet=uno::Any(void), 
aOutParamIndex=empty uno::Sequence, aOutParam=empty uno::Sequence, 
bRaiseError=true, pCaller=0x7fffffffc670) at 
.../libreoffice/sfx2/source/doc/objmisc.cxx:1439
        #35 0x00007ffff440c8ea in SfxObjectShell::CallXScript(rtl::OUString 
const&, com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&, 
com::sun::star::uno::Any&, com::sun::star::uno::Sequence<short>&, 
com::sun::star::uno::Sequence<com::sun::star::uno::Any>&, bool, 
com::sun::star::uno::Any const*)
            (this=0x55555794e5c0, 
rScriptURL="vnd.sun.star.script:Standard.Module1.TestFocus?language=Basic&location=document",
 aParams=uno::Sequence of length 1 = {...}, aRet=uno::Any(void), 
aOutParamIndex=empty uno::Sequence, aOutParam=empty uno::Sequence, 
bRaiseError=true, pCaller=0x7fffffffc670) at 
.../libreoffice/sfx2/source/doc/objmisc.cxx:1468
        #36 0x00007ffff1904e37 in svxform::(anonymous 
namespace)::NewStyleUNOScript::invoke(com::sun::star::uno::Sequence<com::sun::star::uno::Any>
 const&, com::sun::star::uno::Any&)
            (this=0x55555e778920, _rArguments=uno::Sequence of length 1 = 
{...}, _rSynchronousResult=uno::Any(void)) at 
.../libreoffice/svx/source/form/fmscriptingenv.cxx:831
        #37 0x00007ffff1905461 in 
svxform::FormScriptingEnvironment::doFireScriptEvent(com::sun::star::script::ScriptEvent
 const&, com::sun::star::uno::Any*) (this=0x55555c8e5f10, _rEvent=..., 
_pSynchronousResult=0x0)
            at .../libreoffice/svx/source/form/fmscriptingenv.cxx:905
        #38 0x00007ffff1904264 in 
svxform::FormScriptListener::impl_doFireScriptEvent_nothrow(std::unique_lock<std::mutex>&,
 com::sun::star::script::ScriptEvent const&, com::sun::star::uno::Any*)
            (this=0x55555c8e80e0, _rGuard=..., _rEvent=..., 
_pSynchronousResult=0x0) at 
.../libreoffice/svx/source/form/fmscriptingenv.cxx:684
        #39 0x00007ffff190469f in 
svxform::FormScriptListener::OnAsyncScriptEvent(void*) (this=0x55555c8e80e0, 
p=0x55555e778870) at .../libreoffice/svx/source/form/fmscriptingenv.cxx:744
        #40 0x00007ffff19045eb in 
svxform::FormScriptListener::LinkStubOnAsyncScriptEvent(void*, void*) 
(instance=0x55555c8e80e0, data=0x55555e778870) at 
.../libreoffice/svx/source/form/fmscriptingenv.cxx:733
        #41 0x00007fffeddb80ed in Link<void*, void>::Call(void*) const 
(this=0x55555e7788c8, data=0x55555e778870) at 
.../libreoffice/include/tools/link.hxx:111
        #42 0x00007fffeddb51aa in ImplHandleUserEvent(ImplSVEvent*) 
(pSVEvent=0x55555e7788c0) at .../libreoffice/vcl/source/window/winproc.cxx:2287
        #43 0x00007fffeddb70d7 in ImplWindowFrameProc(vcl::Window*, SalEvent, 
void const*) (_pWindow=0x555556c6da40, nEvent=SalEvent::UserEvent, 
pEvent=0x55555e7788c0)
            at .../libreoffice/vcl/source/window/winproc.cxx:2851
        #44 0x00007fffe2e98caa in SalFrame::CallCallback(SalEvent, void const*) 
const (this=0x555556c6f760, nEvent=SalEvent::UserEvent, pEvent=0x55555e7788c0) 
at .../libreoffice/vcl/inc/salframe.hxx:310
        #45 0x00007fffe2eb8973 in 
QtInstance::ProcessEvent(SalUserEventList::SalUserEvent) (this=0x55555573db20, 
aEvent=...) at .../libreoffice/vcl/qt5/QtInstance.cxx:484
        #46 0x00007fffee46593b in operator()() const (__closure=0x7fffffffcc20) 
at .../libreoffice/vcl/source/app/salusereventlist.cxx:119
        #47 0x00007fffee465c0f in SalUserEventList::DispatchUserEvents(bool) 
(this=0x55555573db58, bHandleAllCurrentEvents=false) at 
.../libreoffice/vcl/source/app/salusereventlist.cxx:120
        #48 0x00007fffe2eb8458 in QtInstance::ImplYield(bool, bool) 
(this=0x55555573db20, bWait=true, bHandleAllCurrentEvents=false) at 
.../libreoffice/vcl/qt5/QtInstance.cxx:410
        #49 0x00007fffe2eb8603 in QtInstance::DoYield(bool, bool) 
(this=0x55555573db20, bWait=true, bHandleAllCurrentEvents=false) at 
.../libreoffice/vcl/qt5/QtInstance.cxx:432
        #50 0x00007fffee5221a8 in ImplYield(bool, bool) (i_bWait=true, 
i_bAllEvents=false) at .../libreoffice/vcl/source/app/svapp.cxx:377
        #51 0x00007fffee522f46 in Application::Yield() () at 
.../libreoffice/vcl/source/app/svapp.cxx:461
        #52 0x00007fffee521e9b in Application::Execute() () at 
.../libreoffice/vcl/source/app/svapp.cxx:355
        #53 0x00007ffff7a36296 in desktop::Desktop::Main() 
(this=0x7fffffffd720) at .../libreoffice/desktop/source/app/app.cxx:1601
        #54 0x00007fffee541f42 in ImplSVMain() () at 
.../libreoffice/vcl/source/app/svmain.cxx:204
        #55 0x00007fffee542077 in SVMain() () at 
.../libreoffice/vcl/source/app/svmain.cxx:236
        #56 0x00007ffff7aa1b81 in soffice_main() () at 
.../libreoffice/desktop/source/app/sofficemain.cxx:94
        #57 0x00005555555549d4 in sal_main () at 
.../libreoffice/desktop/source/app/main.c:51
        #58 0x00005555555549ba in main (argc=2, argv=0x7fffffffd948) at 
.../libreoffice/desktop/source/app/main.c:49
    
    Change-Id: Ib6989cc302419bf44a59bd2fff159257f647726d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157017
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit 2632ce875f9a9c3b0a7861112dbfc48fe17bc2a5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156961
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/include/svtools/editbrowsebox.hxx 
b/include/svtools/editbrowsebox.hxx
index ba8f586bdf79..c89a396a9dc7 100644
--- a/include/svtools/editbrowsebox.hxx
+++ b/include/svtools/editbrowsebox.hxx
@@ -368,7 +368,7 @@ namespace svt
             int nStartPos, nEndPos;
             weld::Entry& rEntry = m_rEdit.get_widget();
             rEntry.get_selection_bounds(nStartPos, nEndPos);
-            return rEntry.get_text().copy(nStartPos, nEndPos - nStartPos);
+            return rEntry.get_text().copy(std::min(nStartPos, nEndPos), 
std::abs(nEndPos - nStartPos));
         }
 
         virtual bool IsValueChangedFromSaved() const override

Reply via email to