Index: source/i18n/rematch.cpp |
=================================================================== |
--- source/i18n/rematch.cpp (revision 98343) |
+++ source/i18n/rematch.cpp (working copy) |
@@ -5598,6 +5598,7 @@ |
const UChar *foldChars = NULL; |
int32_t foldOffset, foldLength; |
UChar32 c; |
+ UBool c_is_valid = FALSE; |
#ifdef REGEX_SMART_BACKTRACKING |
int32_t originalInputIdx = fp->fInputIdx; |
@@ -5607,10 +5608,16 @@ |
foldOffset = foldLength = 0; |
while (patternChars < patternEnd && success) { |
- if(foldOffset < foldLength) { |
+ if (fp->fInputIdx >= fActiveLimit) { |
+ // don't read past end of string |
+ } else if(foldOffset < foldLength) { |
U16_NEXT_UNSAFE(foldChars, foldOffset, c); |
+ c_is_valid = TRUE; |
} else { |
jungshik at Google
2011/09/14 18:35:29
How about rewritting the above if - elseif - else
Brad Chen
2011/09/14 19:10:06
Done. Note this makes the patch quite a bit longer
|
+ // test pre-condition of U16_NEXT: i < length |
+ U_ASSERT(fp->fInputIdx < fActiveLimit); |
U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); |
+ c_is_valid = TRUE; |
foldLength = ucase_toFullFolding(csp, c, &foldChars, U_FOLD_CASE_DEFAULT); |
if(foldLength >= 0) { |
if(foldLength <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle chars that fold to 0-length strings |
@@ -5623,7 +5630,7 @@ |
} |
} |
- if (fp->fInputIdx <= fActiveLimit) { |
+ if (fp->fInputIdx <= fActiveLimit && c_is_valid) { |
if (U_IS_BMP(c)) { |
success = (*patternChars == c); |
patternChars += 1; |
@@ -6070,4 +6077,3 @@ |
U_NAMESPACE_END |
#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS |
- |