ICU-11832 some better error checking based on static code analysis

X-SVN-Rev: 37930
This commit is contained in:
Markus Scherer 2015-09-10 01:42:34 +00:00
parent 94fe10c710
commit 0f0c7656d3
12 changed files with 168 additions and 52 deletions

View File

@ -1,6 +1,6 @@
/* /*
***************************************************************************** *****************************************************************************
* Copyright (C) 1996-2014, International Business Machines Corporation and * Copyright (C) 1996-2015, International Business Machines Corporation and
* others. All Rights Reserved. * others. All Rights Reserved.
***************************************************************************** *****************************************************************************
*/ */
@ -508,6 +508,13 @@ Hashtable *CanonicalIterator::extract(Hashtable *fillinResult, UChar32 comp, con
int32_t inputLen=temp.length(); int32_t inputLen=temp.length();
UnicodeString decompString; UnicodeString decompString;
nfd.normalize(temp, decompString, status); nfd.normalize(temp, decompString, status);
if (U_FAILURE(status)) {
return NULL;
}
if (decompString.isBogus()) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
const UChar *decomp=decompString.getBuffer(); const UChar *decomp=decompString.getBuffer();
int32_t decompLen=decompString.length(); int32_t decompLen=decompString.length();

View File

@ -312,6 +312,9 @@ static void uplug_queryPlug(UPlugData *plug, UErrorCode *status) {
static void uplug_loadPlug(UPlugData *plug, UErrorCode *status) { static void uplug_loadPlug(UPlugData *plug, UErrorCode *status) {
if(U_FAILURE(*status)) {
return NULL;
}
if(!plug->awaitingLoad || (plug->level < UPLUG_LEVEL_LOW) ) { /* shouldn't happen. Plugin hasn'tbeen loaded yet.*/ if(!plug->awaitingLoad || (plug->level < UPLUG_LEVEL_LOW) ) { /* shouldn't happen. Plugin hasn'tbeen loaded yet.*/
*status = U_INTERNAL_PROGRAM_ERROR; *status = U_INTERNAL_PROGRAM_ERROR;
return; return;
@ -357,13 +360,11 @@ static UPlugData *uplug_allocateEmptyPlug(UErrorCode *status)
static UPlugData *uplug_allocatePlug(UPlugEntrypoint *entrypoint, const char *config, void *lib, const char *symName, static UPlugData *uplug_allocatePlug(UPlugEntrypoint *entrypoint, const char *config, void *lib, const char *symName,
UErrorCode *status) { UErrorCode *status) {
UPlugData *plug; UPlugData *plug = uplug_allocateEmptyPlug(status);
if(U_FAILURE(*status)) { if(U_FAILURE(*status)) {
return NULL; return NULL;
} }
plug = uplug_allocateEmptyPlug(status);
if(config!=NULL) { if(config!=NULL) {
uprv_strncpy(plug->config, config, UPLUG_NAME_MAX); uprv_strncpy(plug->config, config, UPLUG_NAME_MAX);
} else { } else {

View File

@ -1,8 +1,7 @@
// //
// file: rbbiscan.cpp // file: rbbiscan.cpp
// //
// Copyright (C) 2002-2014, International Business Machines Corporation and others. // Copyright (C) 2002-2015, International Business Machines Corporation and others.
// All Rights Reserved. // All Rights Reserved.
// //
// This file contains the Rule Based Break Iterator Rule Builder functions for // This file contains the Rule Based Break Iterator Rule Builder functions for
@ -211,6 +210,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
fixOpStack(RBBINode::precOpCat); fixOpStack(RBBINode::precOpCat);
RBBINode *operandNode = fNodeStack[fNodeStackPtr--]; RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
RBBINode *orNode = pushNewNode(RBBINode::opOr); RBBINode *orNode = pushNewNode(RBBINode::opOr);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
orNode->fLeftChild = operandNode; orNode->fLeftChild = operandNode;
operandNode->fParent = orNode; operandNode->fParent = orNode;
} }
@ -225,6 +227,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
fixOpStack(RBBINode::precOpCat); fixOpStack(RBBINode::precOpCat);
RBBINode *operandNode = fNodeStack[fNodeStackPtr--]; RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
RBBINode *catNode = pushNewNode(RBBINode::opCat); RBBINode *catNode = pushNewNode(RBBINode::opCat);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
catNode->fLeftChild = operandNode; catNode->fLeftChild = operandNode;
operandNode->fParent = catNode; operandNode->fParent = catNode;
} }
@ -320,6 +325,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
RBBINode *thisRule = fNodeStack[fNodeStackPtr]; RBBINode *thisRule = fNodeStack[fNodeStackPtr];
RBBINode *endNode = pushNewNode(RBBINode::endMark); RBBINode *endNode = pushNewNode(RBBINode::endMark);
RBBINode *catNode = pushNewNode(RBBINode::opCat); RBBINode *catNode = pushNewNode(RBBINode::opCat);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
fNodeStackPtr -= 2; fNodeStackPtr -= 2;
catNode->fLeftChild = thisRule; catNode->fLeftChild = thisRule;
catNode->fRightChild = endNode; catNode->fRightChild = endNode;
@ -347,6 +355,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
RBBINode *thisRule = fNodeStack[fNodeStackPtr]; RBBINode *thisRule = fNodeStack[fNodeStackPtr];
RBBINode *prevRules = *destRules; RBBINode *prevRules = *destRules;
RBBINode *orNode = pushNewNode(RBBINode::opOr); RBBINode *orNode = pushNewNode(RBBINode::opOr);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
orNode->fLeftChild = prevRules; orNode->fLeftChild = prevRules;
prevRules->fParent = orNode; prevRules->fParent = orNode;
orNode->fRightChild = thisRule; orNode->fRightChild = thisRule;
@ -387,6 +398,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
{ {
RBBINode *operandNode = fNodeStack[fNodeStackPtr--]; RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
RBBINode *plusNode = pushNewNode(RBBINode::opPlus); RBBINode *plusNode = pushNewNode(RBBINode::opPlus);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
plusNode->fLeftChild = operandNode; plusNode->fLeftChild = operandNode;
operandNode->fParent = plusNode; operandNode->fParent = plusNode;
} }
@ -396,6 +410,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
{ {
RBBINode *operandNode = fNodeStack[fNodeStackPtr--]; RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
RBBINode *qNode = pushNewNode(RBBINode::opQuestion); RBBINode *qNode = pushNewNode(RBBINode::opQuestion);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
qNode->fLeftChild = operandNode; qNode->fLeftChild = operandNode;
operandNode->fParent = qNode; operandNode->fParent = qNode;
} }
@ -405,6 +422,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
{ {
RBBINode *operandNode = fNodeStack[fNodeStackPtr--]; RBBINode *operandNode = fNodeStack[fNodeStackPtr--];
RBBINode *starNode = pushNewNode(RBBINode::opStar); RBBINode *starNode = pushNewNode(RBBINode::opStar);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
starNode->fLeftChild = operandNode; starNode->fLeftChild = operandNode;
operandNode->fParent = starNode; operandNode->fParent = starNode;
} }
@ -418,6 +438,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
// sets that just happen to contain only one character. // sets that just happen to contain only one character.
{ {
n = pushNewNode(RBBINode::setRef); n = pushNewNode(RBBINode::setRef);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
findSetFor(UnicodeString(fC.fChar), n); findSetFor(UnicodeString(fC.fChar), n);
n->fFirstPos = fScanIndex; n->fFirstPos = fScanIndex;
n->fLastPos = fNextIndex; n->fLastPos = fNextIndex;
@ -429,6 +452,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
// scanned a ".", meaning match any single character. // scanned a ".", meaning match any single character.
{ {
n = pushNewNode(RBBINode::setRef); n = pushNewNode(RBBINode::setRef);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
findSetFor(UnicodeString(TRUE, kAny, 3), n); findSetFor(UnicodeString(TRUE, kAny, 3), n);
n->fFirstPos = fScanIndex; n->fFirstPos = fScanIndex;
n->fLastPos = fNextIndex; n->fLastPos = fNextIndex;
@ -439,6 +465,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
case doSlash: case doSlash:
// Scanned a '/', which identifies a look-ahead break position in a rule. // Scanned a '/', which identifies a look-ahead break position in a rule.
n = pushNewNode(RBBINode::lookAhead); n = pushNewNode(RBBINode::lookAhead);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
n->fVal = fRuleNum; n->fVal = fRuleNum;
n->fFirstPos = fScanIndex; n->fFirstPos = fScanIndex;
n->fLastPos = fNextIndex; n->fLastPos = fNextIndex;
@ -450,6 +479,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
case doStartTagValue: case doStartTagValue:
// Scanned a '{', the opening delimiter for a tag value within a rule. // Scanned a '{', the opening delimiter for a tag value within a rule.
n = pushNewNode(RBBINode::tag); n = pushNewNode(RBBINode::tag);
if (U_FAILURE(*fRB->fStatus)) {
break;
}
n->fVal = 0; n->fVal = 0;
n->fFirstPos = fScanIndex; n->fFirstPos = fScanIndex;
n->fLastPos = fNextIndex; n->fLastPos = fNextIndex;
@ -560,7 +592,7 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
returnVal = FALSE; returnVal = FALSE;
break; break;
} }
return returnVal; return returnVal && U_SUCCESS(*fRB->fStatus);
} }
@ -1051,6 +1083,9 @@ void RBBIRuleScanner::parse() {
if (fRB->fReverseTree == NULL) { if (fRB->fReverseTree == NULL) {
fRB->fReverseTree = pushNewNode(RBBINode::opStar); fRB->fReverseTree = pushNewNode(RBBINode::opStar);
RBBINode *operand = pushNewNode(RBBINode::setRef); RBBINode *operand = pushNewNode(RBBINode::setRef);
if (U_FAILURE(*fRB->fStatus)) {
return;
}
findSetFor(UnicodeString(TRUE, kAny, 3), operand); findSetFor(UnicodeString(TRUE, kAny, 3), operand);
fRB->fReverseTree->fLeftChild = operand; fRB->fReverseTree->fLeftChild = operand;
operand->fParent = fRB->fReverseTree; operand->fParent = fRB->fReverseTree;
@ -1103,6 +1138,9 @@ void RBBIRuleScanner::printNodeStack(const char *title) {
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
RBBINode *RBBIRuleScanner::pushNewNode(RBBINode::NodeType t) { RBBINode *RBBIRuleScanner::pushNewNode(RBBINode::NodeType t) {
if (U_FAILURE(*fRB->fStatus)) {
return NULL;
}
fNodeStackPtr++; fNodeStackPtr++;
if (fNodeStackPtr >= kStackSize) { if (fNodeStackPtr >= kStackSize) {
error(U_BRK_INTERNAL_ERROR); error(U_BRK_INTERNAL_ERROR);
@ -1192,6 +1230,9 @@ void RBBIRuleScanner::scanSet() {
RBBINode *n; RBBINode *n;
n = pushNewNode(RBBINode::setRef); n = pushNewNode(RBBINode::setRef);
if (U_FAILURE(*fRB->fStatus)) {
return;
}
n->fFirstPos = startPos; n->fFirstPos = startPos;
n->fLastPos = fNextIndex; n->fLastPos = fNextIndex;
fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText); fRB->fRules.extractBetween(n->fFirstPos, n->fLastPos, n->fText);

View File

@ -594,6 +594,9 @@ void UnicodeString::swap(UnicodeString &other) U_NOEXCEPT {
UnicodeString UnicodeString::unescape() const { UnicodeString UnicodeString::unescape() const {
UnicodeString result(length(), (UChar32)0, (int32_t)0); // construct with capacity UnicodeString result(length(), (UChar32)0, (int32_t)0); // construct with capacity
if (result.isBogus()) {
return result;
}
const UChar *array = getBuffer(); const UChar *array = getBuffer();
int32_t len = length(); int32_t len = length();
int32_t prev = 0; int32_t prev = 0;

View File

@ -1,7 +1,7 @@
/* /*
******************************************************************************* *******************************************************************************
* *
* Copyright (C) 2005-2014, International Business Machines * Copyright (C) 2005-2015, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
* *
******************************************************************************* *******************************************************************************
@ -2028,6 +2028,9 @@ utext_openReplaceable(UText *ut, Replaceable *rep, UErrorCode *status)
return NULL; return NULL;
} }
ut = utext_setup(ut, sizeof(ReplExtra), status); ut = utext_setup(ut, sizeof(ReplExtra), status);
if(U_FAILURE(*status)) {
return ut;
}
ut->providerProperties = I32_FLAG(UTEXT_PROVIDER_WRITABLE); ut->providerProperties = I32_FLAG(UTEXT_PROVIDER_WRITABLE);
if(rep->hasMetaData()) { if(rep->hasMetaData()) {
@ -2733,6 +2736,9 @@ charIterTextClone(UText *dest, const UText *src, UBool deep, UErrorCode * status
CharacterIterator *srcCI =(CharacterIterator *)src->context; CharacterIterator *srcCI =(CharacterIterator *)src->context;
srcCI = srcCI->clone(); srcCI = srcCI->clone();
dest = utext_openCharacterIterator(dest, srcCI, status); dest = utext_openCharacterIterator(dest, srcCI, status);
if (U_FAILURE(*status)) {
return dest;
}
// cast off const on getNativeIndex. // cast off const on getNativeIndex.
// For CharacterIterator based UTexts, this is safe, the operation is const. // For CharacterIterator based UTexts, this is safe, the operation is const.
int64_t ix = utext_getNativeIndex((UText *)src); int64_t ix = utext_getNativeIndex((UText *)src);

View File

@ -1,6 +1,6 @@
/* /*
******************************************************************************* *******************************************************************************
* Copyright (C) 2010-2014, International Business Machines * Copyright (C) 2010-2015, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
******************************************************************************* *******************************************************************************
* file name: uts46.cpp * file name: uts46.cpp
@ -180,7 +180,7 @@ private:
int32_t int32_t
markBadACELabel(UnicodeString &dest, markBadACELabel(UnicodeString &dest,
int32_t labelStart, int32_t labelLength, int32_t labelStart, int32_t labelLength,
UBool toASCII, IDNAInfo &info) const; UBool toASCII, IDNAInfo &info, UErrorCode &errorCode) const;
void void
checkLabelBiDi(const UChar *label, int32_t labelLength, IDNAInfo &info) const; checkLabelBiDi(const UChar *label, int32_t labelLength, IDNAInfo &info) const;
@ -587,6 +587,9 @@ UTS46::processUnicode(const UnicodeString &src,
int32_t int32_t
UTS46::mapDevChars(UnicodeString &dest, int32_t labelStart, int32_t mappingStart, UTS46::mapDevChars(UnicodeString &dest, int32_t labelStart, int32_t mappingStart,
UErrorCode &errorCode) const { UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return 0;
}
int32_t length=dest.length(); int32_t length=dest.length();
UChar *s=dest.getBuffer(dest[mappingStart]==0xdf ? length+1 : length); UChar *s=dest.getBuffer(dest[mappingStart]==0xdf ? length+1 : length);
if(s==NULL) { if(s==NULL) {
@ -644,6 +647,9 @@ UTS46::mapDevChars(UnicodeString &dest, int32_t labelStart, int32_t mappingStart
uts46Norm2.normalize(dest.tempSubString(labelStart), normalized, errorCode); uts46Norm2.normalize(dest.tempSubString(labelStart), normalized, errorCode);
if(U_SUCCESS(errorCode)) { if(U_SUCCESS(errorCode)) {
dest.replace(labelStart, 0x7fffffff, normalized); dest.replace(labelStart, 0x7fffffff, normalized);
if(dest.isBogus()) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
}
return dest.length(); return dest.length();
} }
} }
@ -665,9 +671,16 @@ isNonASCIIDisallowedSTD3Valid(UChar32 c) {
// Returns labelLength (= the new label length). // Returns labelLength (= the new label length).
static int32_t static int32_t
replaceLabel(UnicodeString &dest, int32_t destLabelStart, int32_t destLabelLength, replaceLabel(UnicodeString &dest, int32_t destLabelStart, int32_t destLabelLength,
const UnicodeString &label, int32_t labelLength) { const UnicodeString &label, int32_t labelLength, UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) {
return 0;
}
if(&label!=&dest) { if(&label!=&dest) {
dest.replace(destLabelStart, destLabelLength, label); dest.replace(destLabelStart, destLabelLength, label);
if(dest.isBogus()) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
return 0;
}
} }
return labelLength; return labelLength;
} }
@ -677,6 +690,9 @@ UTS46::processLabel(UnicodeString &dest,
int32_t labelStart, int32_t labelLength, int32_t labelStart, int32_t labelLength,
UBool toASCII, UBool toASCII,
IDNAInfo &info, UErrorCode &errorCode) const { IDNAInfo &info, UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return 0;
}
UnicodeString fromPunycode; UnicodeString fromPunycode;
UnicodeString *labelString; UnicodeString *labelString;
const UChar *label=dest.getBuffer()+labelStart; const UChar *label=dest.getBuffer()+labelStart;
@ -711,7 +727,7 @@ UTS46::processLabel(UnicodeString &dest,
fromPunycode.releaseBuffer(unicodeLength); fromPunycode.releaseBuffer(unicodeLength);
if(U_FAILURE(punycodeErrorCode)) { if(U_FAILURE(punycodeErrorCode)) {
info.labelErrors|=UIDNA_ERROR_PUNYCODE; info.labelErrors|=UIDNA_ERROR_PUNYCODE;
return markBadACELabel(dest, labelStart, labelLength, toASCII, info); return markBadACELabel(dest, labelStart, labelLength, toASCII, info, errorCode);
} }
// Check for NFC, and for characters that are not // Check for NFC, and for characters that are not
// valid or deviation characters according to the normalizer. // valid or deviation characters according to the normalizer.
@ -726,7 +742,7 @@ UTS46::processLabel(UnicodeString &dest,
} }
if(!isValid) { if(!isValid) {
info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL; info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL;
return markBadACELabel(dest, labelStart, labelLength, toASCII, info); return markBadACELabel(dest, labelStart, labelLength, toASCII, info, errorCode);
} }
labelString=&fromPunycode; labelString=&fromPunycode;
label=fromPunycode.getBuffer(); label=fromPunycode.getBuffer();
@ -739,7 +755,8 @@ UTS46::processLabel(UnicodeString &dest,
// Validity check // Validity check
if(labelLength==0) { if(labelLength==0) {
info.labelErrors|=UIDNA_ERROR_EMPTY_LABEL; info.labelErrors|=UIDNA_ERROR_EMPTY_LABEL;
return replaceLabel(dest, destLabelStart, destLabelLength, *labelString, labelLength); return replaceLabel(dest, destLabelStart, destLabelLength,
*labelString, labelLength, errorCode);
} }
// labelLength>0 // labelLength>0
if(labelLength>=4 && label[2]==0x2d && label[3]==0x2d) { if(labelLength>=4 && label[2]==0x2d && label[3]==0x2d) {
@ -861,7 +878,7 @@ UTS46::processLabel(UnicodeString &dest,
info.labelErrors|=UIDNA_ERROR_LABEL_TOO_LONG; info.labelErrors|=UIDNA_ERROR_LABEL_TOO_LONG;
} }
return replaceLabel(dest, destLabelStart, destLabelLength, return replaceLabel(dest, destLabelStart, destLabelLength,
punycode, punycodeLength); punycode, punycodeLength, errorCode);
} else { } else {
// all-ASCII label // all-ASCII label
if(labelLength>63) { if(labelLength>63) {
@ -874,10 +891,11 @@ UTS46::processLabel(UnicodeString &dest,
// then leave it but make sure it does not look valid. // then leave it but make sure it does not look valid.
if(wasPunycode) { if(wasPunycode) {
info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL; info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL;
return markBadACELabel(dest, destLabelStart, destLabelLength, toASCII, info); return markBadACELabel(dest, destLabelStart, destLabelLength, toASCII, info, errorCode);
} }
} }
return replaceLabel(dest, destLabelStart, destLabelLength, *labelString, labelLength); return replaceLabel(dest, destLabelStart, destLabelLength,
*labelString, labelLength, errorCode);
} }
// Make sure an ACE label does not look valid. // Make sure an ACE label does not look valid.
@ -886,7 +904,10 @@ UTS46::processLabel(UnicodeString &dest,
int32_t int32_t
UTS46::markBadACELabel(UnicodeString &dest, UTS46::markBadACELabel(UnicodeString &dest,
int32_t labelStart, int32_t labelLength, int32_t labelStart, int32_t labelLength,
UBool toASCII, IDNAInfo &info) const { UBool toASCII, IDNAInfo &info, UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return 0;
}
UBool disallowNonLDHDot=(options&UIDNA_USE_STD3_RULES)!=0; UBool disallowNonLDHDot=(options&UIDNA_USE_STD3_RULES)!=0;
UBool isASCII=TRUE; UBool isASCII=TRUE;
UBool onlyLDH=TRUE; UBool onlyLDH=TRUE;
@ -914,6 +935,10 @@ UTS46::markBadACELabel(UnicodeString &dest,
} while(++s<limit); } while(++s<limit);
if(onlyLDH) { if(onlyLDH) {
dest.insert(labelStart+labelLength, (UChar)0xfffd); dest.insert(labelStart+labelLength, (UChar)0xfffd);
if(dest.isBogus()) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
return 0;
}
++labelLength; ++labelLength;
} else { } else {
if(toASCII && isASCII && labelLength>63) { if(toASCII && isASCII && labelLength>63) {

View File

@ -1,7 +1,7 @@
/* /*
****************************************************************************** ******************************************************************************
* Copyright (C) 1999-2010, International Business Machines Corporation and * * Copyright (C) 1999-2015, International Business Machines Corporation and
* others. All Rights Reserved. * * others. All Rights Reserved.
****************************************************************************** ******************************************************************************
* Date Name Description * Date Name Description
* 10/22/99 alan Creation. * 10/22/99 alan Creation.
@ -196,6 +196,9 @@ int32_t UVector32::indexOf(int32_t key, int32_t startIndex) const {
UBool UVector32::expandCapacity(int32_t minimumCapacity, UErrorCode &status) { UBool UVector32::expandCapacity(int32_t minimumCapacity, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (minimumCapacity < 0) { if (minimumCapacity < 0) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return FALSE; return FALSE;

View File

@ -1,7 +1,7 @@
/* /*
****************************************************************************** ******************************************************************************
* Copyright (C) 1999-2010, International Business Machines Corporation and * * Copyright (C) 1999-2015, International Business Machines Corporation and
* others. All Rights Reserved. * * others. All Rights Reserved.
****************************************************************************** ******************************************************************************
*/ */
@ -114,6 +114,9 @@ void UVector64::removeAllElements(void) {
} }
UBool UVector64::expandCapacity(int32_t minimumCapacity, UErrorCode &status) { UBool UVector64::expandCapacity(int32_t minimumCapacity, UErrorCode &status) {
if (U_FAILURE(status)) {
return FALSE;
}
if (minimumCapacity < 0) { if (minimumCapacity < 0) {
status = U_ILLEGAL_ARGUMENT_ERROR; status = U_ILLEGAL_ARGUMENT_ERROR;
return FALSE; return FALSE;

View File

@ -225,10 +225,6 @@ void RegexMatcher::init(UErrorCode &status) {
fInput = NULL; fInput = NULL;
fInputLength = 0; fInputLength = 0;
fInputUniStrMaybeMutable = FALSE; fInputUniStrMaybeMutable = FALSE;
if (U_FAILURE(status)) {
fDeferredStatus = status;
}
} }
// //
@ -2500,6 +2496,10 @@ REStackFrame *RegexMatcher::resetStack() {
fStack->removeAllElements(); fStack->removeAllElements();
REStackFrame *iFrame = (REStackFrame *)fStack->reserveBlock(fPattern->fFrameSize, fDeferredStatus); REStackFrame *iFrame = (REStackFrame *)fStack->reserveBlock(fPattern->fFrameSize, fDeferredStatus);
if(U_FAILURE(fDeferredStatus)) {
return NULL;
}
int32_t i; int32_t i;
for (i=0; i<fPattern->fFrameSize-RESTACKFRAME_HDRCOUNT; i++) { for (i=0; i<fPattern->fFrameSize-RESTACKFRAME_HDRCOUNT; i++) {
iFrame->fExtra[i] = -1; iFrame->fExtra[i] = -1;
@ -2687,9 +2687,12 @@ void RegexMatcher::IncrementTime(UErrorCode &status) {
// //
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
inline REStackFrame *RegexMatcher::StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status) { inline REStackFrame *RegexMatcher::StateSave(REStackFrame *fp, int64_t savePatIdx, UErrorCode &status) {
if (U_FAILURE(status)) {
return fp;
}
// push storage for a new frame. // push storage for a new frame.
int64_t *newFP = fStack->reserveBlock(fFrameSize, status); int64_t *newFP = fStack->reserveBlock(fFrameSize, status);
if (newFP == NULL) { if (U_FAILURE(status)) {
// Failure on attempted stack expansion. // Failure on attempted stack expansion.
// Stack function set some other error code, change it to a more // Stack function set some other error code, change it to a more
// specific one for regular expressions. // specific one for regular expressions.
@ -2781,6 +2784,10 @@ void RegexMatcher::MatchAt(int64_t startIdx, UBool toEnd, UErrorCode &status) {
fFrameSize = fPattern->fFrameSize; fFrameSize = fPattern->fFrameSize;
REStackFrame *fp = resetStack(); REStackFrame *fp = resetStack();
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return;
}
fp->fPatIdx = 0; fp->fPatIdx = 0;
fp->fInputIdx = startIdx; fp->fInputIdx = startIdx;
@ -4344,6 +4351,10 @@ void RegexMatcher::MatchChunkAt(int32_t startIdx, UBool toEnd, UErrorCode &statu
fFrameSize = fPattern->fFrameSize; fFrameSize = fPattern->fFrameSize;
REStackFrame *fp = resetStack(); REStackFrame *fp = resetStack();
if (U_FAILURE(fDeferredStatus)) {
status = fDeferredStatus;
return;
}
fp->fPatIdx = 0; fp->fPatIdx = 0;
fp->fInputIdx = startIdx; fp->fInputIdx = startIdx;

View File

@ -1,6 +1,6 @@
/* /*
****************************************************************************** ******************************************************************************
* Copyright (C) 2001-2014, International Business Machines * Copyright (C) 2001-2015, International Business Machines
* Corporation and others. All Rights Reserved. * Corporation and others. All Rights Reserved.
****************************************************************************** ******************************************************************************
* *
@ -34,14 +34,10 @@ U_NAMESPACE_USE
#define DEFAULT_BUFFER_SIZE 16 #define DEFAULT_BUFFER_SIZE 16
#define BUFFER_GROW 8 #define BUFFER_GROW 8
#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
#define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0]) #define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
#define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type)) #define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type))
#define GROW_ARRAY(array, newSize) uprv_realloc((void *) (array), (newSize) * sizeof (array)[0])
#define DELETE_ARRAY(array) uprv_free((void *) (array)) #define DELETE_ARRAY(array) uprv_free((void *) (array))
struct RCEI struct RCEI
@ -63,8 +59,8 @@ struct RCEBuffer
RCEBuffer(); RCEBuffer();
~RCEBuffer(); ~RCEBuffer();
UBool empty() const; UBool isEmpty() const;
void put(uint32_t ce, int32_t ixLow, int32_t ixHigh); void put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode);
const RCEI *get(); const RCEI *get();
}; };
@ -82,15 +78,22 @@ RCEBuffer::~RCEBuffer()
} }
} }
UBool RCEBuffer::empty() const UBool RCEBuffer::isEmpty() const
{ {
return bufferIndex <= 0; return bufferIndex <= 0;
} }
void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh) void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode)
{ {
if (U_FAILURE(errorCode)) {
return;
}
if (bufferIndex >= bufferSize) { if (bufferIndex >= bufferSize) {
RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW); RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW);
if (newBuffer == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
ARRAY_COPY(newBuffer, buffer, bufferSize); ARRAY_COPY(newBuffer, buffer, bufferSize);
@ -137,15 +140,22 @@ void PCEBuffer::reset()
bufferIndex = 0; bufferIndex = 0;
} }
UBool PCEBuffer::empty() const UBool PCEBuffer::isEmpty() const
{ {
return bufferIndex <= 0; return bufferIndex <= 0;
} }
void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh) void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode)
{ {
if (U_FAILURE(errorCode)) {
return;
}
if (bufferIndex >= bufferSize) { if (bufferIndex >= bufferSize) {
PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW); PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW);
if (newBuffer == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
ARRAY_COPY(newBuffer, buffer, bufferSize); ARRAY_COPY(newBuffer, buffer, bufferSize);
@ -381,7 +391,7 @@ UCollationPCE::previousProcessed(
// pceBuffer.reset(); // pceBuffer.reset();
while (pceBuffer.empty()) { while (pceBuffer.isEmpty()) {
// buffer raw CEs up to non-ignorable primary // buffer raw CEs up to non-ignorable primary
RCEBuffer rceb; RCEBuffer rceb;
int32_t ce; int32_t ce;
@ -393,30 +403,33 @@ UCollationPCE::previousProcessed(
low = cei->getOffset(); low = cei->getOffset();
if (ce == UCOL_NULLORDER) { if (ce == UCOL_NULLORDER) {
if (! rceb.empty()) { if (!rceb.isEmpty()) {
break; break;
} }
goto finish; goto finish;
} }
rceb.put((uint32_t)ce, low, high); rceb.put((uint32_t)ce, low, high, *status);
} while ((ce & UCOL_PRIMARYORDERMASK) == 0 || isContinuation(ce)); } while (U_SUCCESS(*status) && ((ce & UCOL_PRIMARYORDERMASK) == 0 || isContinuation(ce)));
// process the raw CEs // process the raw CEs
while (! rceb.empty()) { while (U_SUCCESS(*status) && !rceb.isEmpty()) {
const RCEI *rcei = rceb.get(); const RCEI *rcei = rceb.get();
result = processCE(rcei->ce); result = processCE(rcei->ce);
if (result != UCOL_IGNORABLE) { if (result != UCOL_IGNORABLE) {
pceBuffer.put(result, rcei->low, rcei->high); pceBuffer.put(result, rcei->low, rcei->high, *status);
} }
} }
if (U_FAILURE(*status)) {
return UCOL_PROCESSED_NULLORDER;
}
} }
finish: finish:
if (pceBuffer.empty()) { if (pceBuffer.isEmpty()) {
// **** Is -1 the right value for ixLow, ixHigh? **** // **** Is -1 the right value for ixLow, ixHigh? ****
if (ixLow != NULL) { if (ixLow != NULL) {
*ixLow = -1; *ixLow = -1;

View File

@ -1,6 +1,6 @@
/* /*
********************************************************************** **********************************************************************
* Copyright (C) 2001-2014 IBM and others. All rights reserved. * Copyright (C) 2001-2015 IBM and others. All rights reserved.
********************************************************************** **********************************************************************
* Date Name Description * Date Name Description
* 08/13/2001 synwee Creation. * 08/13/2001 synwee Creation.
@ -69,8 +69,8 @@ struct PCEBuffer
~PCEBuffer(); ~PCEBuffer();
void reset(); void reset();
UBool empty() const; UBool isEmpty() const;
void put(uint64_t ce, int32_t ixLow, int32_t ixHigh); void put(uint64_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode);
const PCEI *get(); const PCEI *get();
}; };

View File

@ -1,6 +1,6 @@
/* /*
/ * / *
* (C) Copyright IBM Corp. 1998-2013 - All Rights Reserved * (C) Copyright IBM Corp. 1998-2015 - All Rights Reserved
* *
*/ */
@ -633,9 +633,9 @@ le_int32 IndicReordering::reorder(const LEUnicode *chars, le_int32 charCount, le
MPreFixups *mpreFixups = NULL; MPreFixups *mpreFixups = NULL;
const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode);
if(classTable==NULL) { if (classTable==NULL) {
success = LE_MEMORY_ALLOCATION_ERROR; success = LE_INTERNAL_ERROR;
return 0; return 0;
} }
if (classTable->scriptFlags & SF_MPRE_FIXUP) { if (classTable->scriptFlags & SF_MPRE_FIXUP) {
@ -1074,6 +1074,9 @@ le_int32 IndicReordering::v2process(const LEUnicode *chars, le_int32 charCount,
LEUnicode *outChars, LEGlyphStorage &glyphStorage) LEUnicode *outChars, LEGlyphStorage &glyphStorage)
{ {
const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode); const IndicClassTable *classTable = IndicClassTable::getScriptClassTable(scriptCode);
if (classTable == NULL) {
return 0;
}
DynamicProperties dynProps[INDIC_BLOCK_SIZE]; DynamicProperties dynProps[INDIC_BLOCK_SIZE];
IndicReordering::getDynamicProperties(dynProps,classTable); IndicReordering::getDynamicProperties(dynProps,classTable);