summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-11-25 15:58:01 +0100
committerAndras Timar <andras.timar@collabora.com>2015-11-28 14:15:55 +0100
commit0afe9b5e0f775fbcc7995f32c5766828d349219b (patch)
tree8d4260e99456e7a909c57b60c7b494d6c781161a /i18npool
parentc088f4a5837e516785cb8566545b577f97e4ff38 (diff)
regex result offsets can be negative if a group was not matched, tdf#94810
"(abc)|(def)" matches "def" with result offset sequences {0,-1,0},{3,-1,3} And thus the assert() calls introduced with 4cf1d290bab29e18e1312b63ff862f5102e00387 and ce91f3c1292f3e9b84157acf10b67ad9ca16719d were hit. Change-Id: I571b6c7d47349a2cc7b1d1e34193b2865012a49f (cherry picked from commit 4dd2d40673299966ad639d799e925e64ae5560cf) Reviewed-on: https://gerrit.libreoffice.org/20174 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mikekaganski@hotmail.com> (cherry picked from commit a38963a40eed7f1d85767b393a316870c31bff5c)
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/search/textsearch.cxx36
1 files changed, 22 insertions, 14 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 472d509691f4..97cceee685bb 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -301,18 +301,22 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta
for ( sal_Int32 k = 0; k < nGroups; k++ )
{
const sal_Int32 nStart = sres.startOffset[k] - nExtraOffset;
- assert(nStart >= 0);
- sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1));
+ // Result offsets are negative (-1) if a group expression was
+ // not matched.
+ if (nStart >= 0)
+ sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1));
// JP 20.6.2001: end is ever exclusive and then don't return
// the position of the next character - return the
// next position behind the last found character!
// "a b c" find "b" must return 2,3 and not 2,4!!!
const sal_Int32 nStop = sres.endOffset[k] - nExtraOffset;
- assert(nStop >= 0);
- if (nStop > 0)
- sres.endOffset[k] = offset[(nStop <= nOffsets ? nStop : nOffsets) - 1] + 1;
- else
- sres.endOffset[k] = offset[0];
+ if (nStop >= 0)
+ {
+ if (nStop > 0)
+ sres.endOffset[k] = offset[(nStop <= nOffsets ? nStop : nOffsets) - 1] + 1;
+ else
+ sres.endOffset[k] = offset[0];
+ }
}
}
}
@@ -404,18 +408,22 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
for ( sal_Int32 k = 0; k < nGroups; k++ )
{
const sal_Int32 nStart = sres.startOffset[k];
- assert(nStart >= 0);
- if (nStart > 0)
- sres.startOffset[k] = offset[(nStart <= nOffsets ? nStart : nOffsets) - 1] + 1;
- else
- sres.startOffset[k] = offset[0];
+ // Result offsets are negative (-1) if a group expression was
+ // not matched.
+ if (nStart >= 0)
+ {
+ if (nStart > 0)
+ sres.startOffset[k] = offset[(nStart <= nOffsets ? nStart : nOffsets) - 1] + 1;
+ else
+ sres.startOffset[k] = offset[0];
+ }
// JP 20.6.2001: end is ever exclusive and then don't return
// the position of the next character - return the
// next position behind the last found character!
// "a b c" find "b" must return 2,3 and not 2,4!!!
const sal_Int32 nStop = sres.endOffset[k];
- assert(nStop >= 0);
- sres.endOffset[k] = (nStop < nOffsets ? offset[nStop] : (offset[nOffsets - 1] + 1));
+ if (nStop >= 0)
+ sres.endOffset[k] = (nStop < nOffsets ? offset[nStop] : (offset[nOffsets - 1] + 1));
}
}
}