summaryrefslogtreecommitdiffstats
path: root/kjs
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2016-04-03 15:21:58 +0200
committerSlávek Banko <slavek.banko@axis.cz>2016-04-03 15:23:17 +0200
commit7e27cf22d45e6c7f85a7059ce3ddcedff51a052e (patch)
tree0ba8dcea26683599ac53061edc9ac1ac5ee87f5a /kjs
parentfef74a0f99c96f857d668432cad4bfd60950e5ee (diff)
downloadtdelibs-7e27cf22d45e6c7f85a7059ce3ddcedff51a052e.tar.gz
tdelibs-7e27cf22d45e6c7f85a7059ce3ddcedff51a052e.zip
Fix occasional Konqueror crashes on kjs/regexp
This relates to old KDE3 commit https://quickgit.kde.org/?p=kdelibs.git&a=commit&h=fee91015 Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit e9d546a6a3c9fb802c5d9c2c7765834599d90ea8)
Diffstat (limited to 'kjs')
-rw-r--r--kjs/regexp.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/kjs/regexp.cpp b/kjs/regexp.cpp
index 06defcc53..e4db2b956 100644
--- a/kjs/regexp.cpp
+++ b/kjs/regexp.cpp
@@ -325,13 +325,15 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
++startPos;
nextPos = startPos;
- while (originalPos[nextPos] < (i + 1))
- ++nextPos;
+ if (i < s.size()) {
+ while (originalPos[nextPos] < (i + 1))
+ ++nextPos;
+ }
} else
#endif
{
startPos = i;
- nextPos = i + 1;
+ nextPos = i + (i < s.size() ? 1 : 0);
}
int baseFlags =
@@ -339,12 +341,13 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
utf8Support == Supported ? PCRE_NO_UTF8_CHECK :
#endif
0;
- if (pcre_exec(pcregex, NULL, buffer, bufferSize, startPos,
- m_notEmpty ? (PCRE_NOTEMPTY | PCRE_ANCHORED | baseFlags) : baseFlags, // see man pcretest
- ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH)
+ int numMatches = pcre_exec(pcregex, NULL, buffer, bufferSize, startPos,
+ m_notEmpty ? (PCRE_NOTEMPTY | PCRE_ANCHORED | baseFlags) : baseFlags, // see man pcretest
+ ovector ? *ovector : 0L, ovecsize);
+ if (numMatches < 0)
{
// Failed to match.
- if ((flgs & Global) && m_notEmpty && ovector)
+ if (numMatches == PCRE_ERROR_NOMATCH && (flgs & Global) && m_notEmpty && ovector && startPos < nextPos)
{
// We set m_notEmpty ourselves, to look for a non-empty match
// (see man pcretest or pcretest.c for details).
@@ -353,8 +356,9 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
fprintf(stderr, "No match after m_notEmpty. +1 and keep going.\n");
#endif
m_notEmpty = 0;
- if (pcre_exec(pcregex, NULL, buffer, bufferSize, nextPos, baseFlags,
- ovector ? *ovector : 0L, ovecsize) == PCRE_ERROR_NOMATCH)
+ numMatches = pcre_exec(pcregex, NULL, buffer, bufferSize, nextPos, baseFlags,
+ ovector ? *ovector : 0L, ovecsize);
+ if (numMatches < 0)
return UString::null;
}
else // done
@@ -364,7 +368,7 @@ UString RegExp::match(const UString &s, int i, int *pos, int **ovector)
// Got a match, proceed with it.
// But fix up the ovector if need be..
if (ovector && originalPos) {
- for (unsigned c = 0; c < 2 * (nrSubPatterns + 1); ++c) {
+ for (unsigned c = 0; c < 2 * TQMIN((unsigned)numMatches, nrSubPatterns+1); ++c) {
if ((*ovector)[c] != -1)
(*ovector)[c] = originalPos[(*ovector)[c]];
}