Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: source/common/uts46.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/common/utext.cpp ('k') | source/common/utypes.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/common/uts46.cpp
diff --git a/source/common/uts46.cpp b/source/common/uts46.cpp
index 80900a019b42f2c9b18f105d631951a3e48caf97..13a1f246c21cc91ee67a2aa2bafe76db85c5bd14 100644
--- a/source/common/uts46.cpp
+++ b/source/common/uts46.cpp
@@ -1,6 +1,6 @@
/*
*******************************************************************************
-* Copyright (C) 2010-2014, International Business Machines
+* Copyright (C) 2010-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: uts46.cpp
@@ -180,7 +180,7 @@ private:
int32_t
markBadACELabel(UnicodeString &dest,
int32_t labelStart, int32_t labelLength,
- UBool toASCII, IDNAInfo &info) const;
+ UBool toASCII, IDNAInfo &info, UErrorCode &errorCode) const;
void
checkLabelBiDi(const UChar *label, int32_t labelLength, IDNAInfo &info) const;
@@ -587,6 +587,9 @@ UTS46::processUnicode(const UnicodeString &src,
int32_t
UTS46::mapDevChars(UnicodeString &dest, int32_t labelStart, int32_t mappingStart,
UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) {
+ return 0;
+ }
int32_t length=dest.length();
UChar *s=dest.getBuffer(dest[mappingStart]==0xdf ? length+1 : length);
if(s==NULL) {
@@ -644,6 +647,9 @@ UTS46::mapDevChars(UnicodeString &dest, int32_t labelStart, int32_t mappingStart
uts46Norm2.normalize(dest.tempSubString(labelStart), normalized, errorCode);
if(U_SUCCESS(errorCode)) {
dest.replace(labelStart, 0x7fffffff, normalized);
+ if(dest.isBogus()) {
+ errorCode=U_MEMORY_ALLOCATION_ERROR;
+ }
return dest.length();
}
}
@@ -665,9 +671,16 @@ isNonASCIIDisallowedSTD3Valid(UChar32 c) {
// Returns labelLength (= the new label length).
static int32_t
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) {
dest.replace(destLabelStart, destLabelLength, label);
+ if(dest.isBogus()) {
+ errorCode=U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
}
return labelLength;
}
@@ -677,6 +690,9 @@ UTS46::processLabel(UnicodeString &dest,
int32_t labelStart, int32_t labelLength,
UBool toASCII,
IDNAInfo &info, UErrorCode &errorCode) const {
+ if(U_FAILURE(errorCode)) {
+ return 0;
+ }
UnicodeString fromPunycode;
UnicodeString *labelString;
const UChar *label=dest.getBuffer()+labelStart;
@@ -711,7 +727,7 @@ UTS46::processLabel(UnicodeString &dest,
fromPunycode.releaseBuffer(unicodeLength);
if(U_FAILURE(punycodeErrorCode)) {
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
// valid or deviation characters according to the normalizer.
@@ -726,7 +742,7 @@ UTS46::processLabel(UnicodeString &dest,
}
if(!isValid) {
info.labelErrors|=UIDNA_ERROR_INVALID_ACE_LABEL;
- return markBadACELabel(dest, labelStart, labelLength, toASCII, info);
+ return markBadACELabel(dest, labelStart, labelLength, toASCII, info, errorCode);
}
labelString=&fromPunycode;
label=fromPunycode.getBuffer();
@@ -739,7 +755,8 @@ UTS46::processLabel(UnicodeString &dest,
// Validity check
if(labelLength==0) {
info.labelErrors|=UIDNA_ERROR_EMPTY_LABEL;
- return replaceLabel(dest, destLabelStart, destLabelLength, *labelString, labelLength);
+ return replaceLabel(dest, destLabelStart, destLabelLength,
+ *labelString, labelLength, errorCode);
}
// labelLength>0
if(labelLength>=4 && label[2]==0x2d && label[3]==0x2d) {
@@ -861,7 +878,7 @@ UTS46::processLabel(UnicodeString &dest,
info.labelErrors|=UIDNA_ERROR_LABEL_TOO_LONG;
}
return replaceLabel(dest, destLabelStart, destLabelLength,
- punycode, punycodeLength);
+ punycode, punycodeLength, errorCode);
} else {
// all-ASCII label
if(labelLength>63) {
@@ -874,10 +891,11 @@ UTS46::processLabel(UnicodeString &dest,
// then leave it but make sure it does not look valid.
if(wasPunycode) {
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.
@@ -886,7 +904,10 @@ UTS46::processLabel(UnicodeString &dest,
int32_t
UTS46::markBadACELabel(UnicodeString &dest,
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 isASCII=TRUE;
UBool onlyLDH=TRUE;
@@ -914,6 +935,10 @@ UTS46::markBadACELabel(UnicodeString &dest,
} while(++s<limit);
if(onlyLDH) {
dest.insert(labelStart+labelLength, (UChar)0xfffd);
+ if(dest.isBogus()) {
+ errorCode=U_MEMORY_ALLOCATION_ERROR;
+ return 0;
+ }
++labelLength;
} else {
if(toASCII && isASCII && labelLength>63) {
« no previous file with comments | « source/common/utext.cpp ('k') | source/common/utypes.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698