summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unotools/source/i18n/textsearch.cxx6
1 files changed, 5 insertions, 1 deletions
diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx
index 5bb4dfd81a4a..12504ccf0882 100644
--- a/unotools/source/i18n/textsearch.cxx
+++ b/unotools/source/i18n/textsearch.cxx
@@ -329,7 +329,11 @@ void TextSearch::ReplaceBackReferences( OUString& rReplaceStr, const OUString &r
{
sal_Int32 nSttReg = rResult.startOffset[j];
sal_Int32 nRegLen = rResult.endOffset[j];
- if( nRegLen > nSttReg )
+ if (nSttReg < 0 || nRegLen < 0) // A "not found" optional capture
+ {
+ nSttReg = nRegLen = 0; // Copy empty string
+ }
+ else if (nRegLen >= nSttReg)
{
nRegLen = nRegLen - nSttReg;
}