sw: fix assert due to invalid nEndPos in SwAutoCorrDoc::ChgAutoCorrWord()

Happens when using a "non-text-only" replacement (which can be created by
selecting text before opening AutoCorrect dialog).

asserts in SvxAutocorrWordList::WordMatches():

  /usr/include/c++/14/string_view:256: constexpr const std::basic_string_view<_CharT, _Traits>::value_type& std::basic_string_view<_CharT, _Traits>::operator[](size_type) const [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; const_reference = const char16_t&; size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.

The "IsTextOnly()" branch adjusts nEndPos, clearly it's needed in the
else branch too.

Change-Id: I442042a5560d8143f1293ac29476aff6e93d7f3b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173476
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
This commit is contained in:
Michael Stahl
2024-09-16 15:44:46 +02:00
parent 857dd6000c
commit eae540e38b

View File

@@ -493,6 +493,10 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
sw::GotoNextLayoutTextFrame(*m_oIndex, m_rEditSh.GetLayout());
pTextNd = m_oIndex->GetNode().GetTextNode();
}
// hmm... the inserted text can have multiple text nodes
// - not sure what the "pos" should point to, but pFrame
// is not changed so try the first node?
nEndPos = sttPos + aCpyPam.GetMark()->GetContentIndex();
bRet = true;
}
aTBlks.EndGetDoc();