ICU-11302 Proper error handling with utext_clone in regular expression implementation.

X-SVN-Rev: 36673
This commit is contained in:
Yoshito Umaoka 2014-10-13 17:46:34 +00:00
parent 547757ebe9
commit ff4fd29a21
3 changed files with 25 additions and 8 deletions

View file

@ -138,6 +138,9 @@ void RegexCompile::compile(
// Prepare the RegexPattern object to receive the compiled pattern.
fRXPat->fPattern = utext_clone(fRXPat->fPattern, pat, FALSE, TRUE, fStatus);
if (U_FAILURE(*fStatus)) {
return;
}
fRXPat->fStaticSets = RegexStaticSets::gStaticSets->fPropSets;
fRXPat->fStaticSets8 = RegexStaticSets::gStaticSets->fPropSets8;

View file

@ -1884,6 +1884,9 @@ RegexMatcher &RegexMatcher::reset(const UnicodeString &input) {
if (fPattern->fNeedsAltInput) {
fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
}
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
fInputLength = utext_nativeLength(fInputText);
reset();
@ -1908,6 +1911,9 @@ RegexMatcher &RegexMatcher::reset(UText *input) {
if (fInputText != input) {
fInputText = utext_clone(fInputText, input, FALSE, TRUE, &fDeferredStatus);
if (fPattern->fNeedsAltInput) fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
fInputLength = utext_nativeLength(fInputText);
delete fInput;

View file

@ -3,7 +3,7 @@
//
/*
***************************************************************************
* Copyright (C) 2002-2013 International Business Machines Corporation *
* Copyright (C) 2002-2014 International Business Machines Corporation *
* and others. All rights reserved. *
***************************************************************************
*/
@ -66,21 +66,29 @@ RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
init();
// Copy simple fields
if ( other.fPatternString == NULL ) {
fDeferredStatus = other.fDeferredStatus;
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
if (other.fPatternString == NULL) {
fPatternString = NULL;
fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
} else {
fPatternString = new UnicodeString(*(other.fPatternString));
UErrorCode status = U_ZERO_ERROR;
fPattern = utext_openConstUnicodeString(NULL, fPatternString, &status);
if (U_FAILURE(status)) {
if (fPatternString == NULL) {
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
return *this;
} else {
fPattern = utext_openConstUnicodeString(NULL, fPatternString, &fDeferredStatus);
}
}
if (U_FAILURE(fDeferredStatus)) {
return *this;
}
fFlags = other.fFlags;
fLiteralText = other.fLiteralText;
fDeferredStatus = other.fDeferredStatus;
fMinMatchLen = other.fMinMatchLen;
fFrameSize = other.fFrameSize;
fDataSize = other.fDataSize;