Skip to content

Commit 6ae61a2

Browse files
authored
Merge branch 'master' into refactor-to-use-validate-string
2 parents fc697ed + e279304 commit 6ae61a2

31 files changed

+509
-5505
lines changed

deps/icu-small/source/common/cmemory.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,14 @@ class MemoryPool : public UMemory {
725725
}
726726

727727
MemoryPool& operator=(MemoryPool&& other) U_NOEXCEPT {
728-
fCount = other.fCount;
729-
fPool = std::move(other.fPool);
730-
other.fCount = 0;
728+
// Since `this` may contain instances that need to be deleted, we can't
729+
// just throw them away and replace them with `other`. The normal way of
730+
// dealing with this in C++ is to swap `this` and `other`, rather than
731+
// simply overwrite: the destruction of `other` can then take care of
732+
// running MemoryPool::~MemoryPool() over the still-to-be-deallocated
733+
// instances.
734+
std::swap(fCount, other.fCount);
735+
std::swap(fPool, other.fPool);
731736
return *this;
732737
}
733738

@@ -796,9 +801,6 @@ class MemoryPool : public UMemory {
796801
template<typename T, int32_t stackCapacity = 8>
797802
class MaybeStackVector : protected MemoryPool<T, stackCapacity> {
798803
public:
799-
using MemoryPool<T, stackCapacity>::MemoryPool;
800-
using MemoryPool<T, stackCapacity>::operator=;
801-
802804
template<typename... Args>
803805
T* emplaceBack(Args&&... args) {
804806
return this->create(args...);

deps/icu-small/source/common/locid.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "unicode/bytestream.h"
3737
#include "unicode/locid.h"
38+
#include "unicode/localebuilder.h"
3839
#include "unicode/strenum.h"
3940
#include "unicode/stringpiece.h"
4041
#include "unicode/uloc.h"
@@ -1028,7 +1029,7 @@ class AliasReplacer {
10281029
// place the the replaced locale ID in out and return true.
10291030
// Otherwise return false for no replacement or error.
10301031
bool replace(
1031-
const Locale& locale, CharString& out, UErrorCode status);
1032+
const Locale& locale, CharString& out, UErrorCode& status);
10321033

10331034
private:
10341035
const char* language;
@@ -1336,10 +1337,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
13361337
// Cannot use nullptr for language because that will construct
13371338
// the default locale, in that case, use "und" to get the correct
13381339
// locale.
1339-
Locale l(language == nullptr ? "und" : language, nullptr, script);
1340+
Locale l = LocaleBuilder()
1341+
.setLanguage(language == nullptr ? "und" : language)
1342+
.setScript(script)
1343+
.build(status);
13401344
l.addLikelySubtags(status);
13411345
const char* likelyRegion = l.getCountry();
1342-
CharString* item = nullptr;
1346+
LocalPointer<CharString> item;
13431347
if (likelyRegion != nullptr && uprv_strlen(likelyRegion) > 0) {
13441348
size_t len = uprv_strlen(likelyRegion);
13451349
const char* foundInReplacement = uprv_strstr(replacement,
@@ -1351,20 +1355,22 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
13511355
*(foundInReplacement-1) == ' ');
13521356
U_ASSERT(foundInReplacement[len] == ' ' ||
13531357
foundInReplacement[len] == '\0');
1354-
item = new CharString(foundInReplacement, (int32_t)len, status);
1358+
item.adoptInsteadAndCheckErrorCode(
1359+
new CharString(foundInReplacement, (int32_t)len, status), status);
13551360
}
13561361
}
1357-
if (item == nullptr) {
1358-
item = new CharString(replacement,
1359-
(int32_t)(firstSpace - replacement), status);
1362+
if (item.isNull() && U_SUCCESS(status)) {
1363+
item.adoptInsteadAndCheckErrorCode(
1364+
new CharString(replacement,
1365+
(int32_t)(firstSpace - replacement), status), status);
13601366
}
13611367
if (U_FAILURE(status)) { return false; }
1362-
if (item == nullptr) {
1368+
if (item.isNull()) {
13631369
status = U_MEMORY_ALLOCATION_ERROR;
13641370
return false;
13651371
}
13661372
replacedRegion = item->data();
1367-
toBeFreed.addElement(item, status);
1373+
toBeFreed.addElement(item.orphan(), status);
13681374
}
13691375
U_ASSERT(!same(region, replacedRegion));
13701376
region = replacedRegion;
@@ -1453,7 +1459,7 @@ AliasReplacer::outputToString(
14531459
int32_t variantsStart = out.length();
14541460
for (int32_t i = 0; i < variants.size(); i++) {
14551461
out.append(SEP_CHAR, status)
1456-
.append((const char*)((UVector*)variants.elementAt(i)),
1462+
.append((const char*)(variants.elementAt(i)),
14571463
status);
14581464
}
14591465
T_CString_toUpperCase(out.data() + variantsStart);
@@ -1470,7 +1476,7 @@ AliasReplacer::outputToString(
14701476
}
14711477

14721478
bool
1473-
AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode status)
1479+
AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status)
14741480
{
14751481
data = AliasData::singleton(status);
14761482
if (U_FAILURE(status)) {
@@ -2453,9 +2459,13 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
24532459
if (U_FAILURE(status)) {
24542460
return;
24552461
}
2462+
if (status == U_STRING_NOT_TERMINATED_WARNING) {
2463+
status = U_ZERO_ERROR;
2464+
}
24562465
int32_t bufferLength = uprv_max((int32_t)(uprv_strlen(fullName) + 1), ULOC_FULLNAME_CAPACITY);
24572466
int32_t newLength = uloc_setKeywordValue(keywordName, keywordValue, fullName,
24582467
bufferLength, &status) + 1;
2468+
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
24592469
/* Handle the case the current buffer is not enough to hold the new id */
24602470
if (status == U_BUFFER_OVERFLOW_ERROR) {
24612471
U_ASSERT(newLength > bufferLength);
@@ -2472,6 +2482,7 @@ Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErro
24722482
fullName = newFullName;
24732483
status = U_ZERO_ERROR;
24742484
uloc_setKeywordValue(keywordName, keywordValue, fullName, newLength, &status);
2485+
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
24752486
} else {
24762487
U_ASSERT(newLength <= bufferLength);
24772488
}

deps/icu-small/source/common/rbbitblb.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1402,12 +1402,13 @@ void RBBITableBuilder::exportTable(void *where) {
14021402
U_ASSERT (sd->fAccepting <= 255);
14031403
U_ASSERT (sd->fLookAhead <= 255);
14041404
U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255);
1405-
row->r8.fAccepting = sd->fAccepting;
1406-
row->r8.fLookAhead = sd->fLookAhead;
1407-
row->r8.fTagsIdx = sd->fTagsIdx;
1405+
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row;
1406+
r8->fAccepting = sd->fAccepting;
1407+
r8->fLookAhead = sd->fLookAhead;
1408+
r8->fTagsIdx = sd->fTagsIdx;
14081409
for (col=0; col<catCount; col++) {
14091410
U_ASSERT (sd->fDtran->elementAti(col) <= kMaxStateFor8BitsTable);
1410-
row->r8.fNextState[col] = sd->fDtran->elementAti(col);
1411+
r8->fNextState[col] = sd->fDtran->elementAti(col);
14111412
}
14121413
} else {
14131414
U_ASSERT (sd->fAccepting <= 0xffff);
@@ -1603,12 +1604,13 @@ void RBBITableBuilder::exportSafeTable(void *where) {
16031604
UnicodeString *rowString = (UnicodeString *)fSafeTable->elementAt(state);
16041605
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen);
16051606
if (use8BitsForSafeTable()) {
1606-
row->r8.fAccepting = 0;
1607-
row->r8.fLookAhead = 0;
1608-
row->r8.fTagsIdx = 0;
1607+
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row;
1608+
r8->fAccepting = 0;
1609+
r8->fLookAhead = 0;
1610+
r8->fTagsIdx = 0;
16091611
for (col=0; col<catCount; col++) {
16101612
U_ASSERT(rowString->charAt(col) <= kMaxStateFor8BitsTable);
1611-
row->r8.fNextState[col] = static_cast<uint8_t>(rowString->charAt(col));
1613+
r8->fNextState[col] = static_cast<uint8_t>(rowString->charAt(col));
16121614
}
16131615
} else {
16141616
row->r16.fAccepting = 0;

deps/icu-small/source/common/uloc.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ uloc_setKeywordValue(const char* keywordName,
877877
if(U_FAILURE(*status)) {
878878
return -1;
879879
}
880+
if (*status == U_STRING_NOT_TERMINATED_WARNING) {
881+
*status = U_ZERO_ERROR;
882+
}
880883
if (keywordName == NULL || keywordName[0] == 0 || bufferCapacity <= 1) {
881884
*status = U_ILLEGAL_ARGUMENT_ERROR;
882885
return 0;
@@ -914,6 +917,7 @@ uloc_setKeywordValue(const char* keywordName,
914917
startSearchHere = (char*)locale_getKeywordsStart(buffer);
915918
if(startSearchHere == NULL || (startSearchHere[1]==0)) {
916919
if(keywordValueLen == 0) { /* no keywords = nothing to remove */
920+
U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING);
917921
return bufLen;
918922
}
919923

@@ -933,6 +937,7 @@ uloc_setKeywordValue(const char* keywordName,
933937
startSearchHere += keywordNameLen;
934938
*startSearchHere++ = '=';
935939
uprv_strcpy(startSearchHere, keywordValueBuffer);
940+
U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING);
936941
return needLen;
937942
} /* end shortcut - no @ */
938943

@@ -1047,13 +1052,27 @@ uloc_setKeywordValue(const char* keywordName,
10471052
if (!handledInputKeyAndValue || U_FAILURE(*status)) {
10481053
/* if input key/value specified removal of a keyword not present in locale, or
10491054
* there was an error in CharString.append, leave original locale alone. */
1055+
U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING);
10501056
return bufLen;
10511057
}
10521058

10531059
// needLen = length of the part before '@'
10541060
needLen = (int32_t)(startSearchHere - buffer);
1055-
return needLen + updatedKeysAndValues.extract(
1061+
// Check to see can we fit the startSearchHere, if not, return
1062+
// U_BUFFER_OVERFLOW_ERROR without copy updatedKeysAndValues into it.
1063+
// We do this because this API function does not behave like most others:
1064+
// It promises never to set a U_STRING_NOT_TERMINATED_WARNING.
1065+
// When the contents fits but without the terminating NUL, in this case we need to not change
1066+
// the buffer contents and return with a buffer overflow error.
1067+
int32_t appendLength = updatedKeysAndValues.length();
1068+
if (appendLength >= bufferCapacity - needLen) {
1069+
*status = U_BUFFER_OVERFLOW_ERROR;
1070+
return needLen + appendLength;
1071+
}
1072+
needLen += updatedKeysAndValues.extract(
10561073
startSearchHere, bufferCapacity - needLen, *status);
1074+
U_ASSERT(*status != U_STRING_NOT_TERMINATED_WARNING);
1075+
return needLen;
10571076
}
10581077

10591078
/* ### ID parsing implementation **************************************************/

deps/icu-small/source/common/unicode/docmain.h

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
* <td>icu::MessageFormat</td>
144144
* </tr>
145145
* <tr>
146+
* <td>List Formatting</td>
147+
* <td>ulistformatter.h</td>
148+
* <td>icu::ListFormatter</td>
149+
* </tr>
150+
* <tr>
146151
* <td>Number Formatting<br/>(includes currency and unit formatting)</td>
147152
* <td>unumberformatter.h, unum.h</td>
148153
* <td>icu::number::NumberFormatter (ICU 60+) or icu::NumberFormat (older versions)</td>

deps/icu-small/source/common/unicode/urename.h

+1
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@
11371137
#define ulocimp_toLanguageTag U_ICU_ENTRY_POINT_RENAME(ulocimp_toLanguageTag)
11381138
#define ulocimp_toLegacyKey U_ICU_ENTRY_POINT_RENAME(ulocimp_toLegacyKey)
11391139
#define ulocimp_toLegacyType U_ICU_ENTRY_POINT_RENAME(ulocimp_toLegacyType)
1140+
#define ultag_getTKeyStart U_ICU_ENTRY_POINT_RENAME(ultag_getTKeyStart)
11401141
#define ultag_isExtensionSubtags U_ICU_ENTRY_POINT_RENAME(ultag_isExtensionSubtags)
11411142
#define ultag_isLanguageSubtag U_ICU_ENTRY_POINT_RENAME(ultag_isLanguageSubtag)
11421143
#define ultag_isPrivateuseValueSubtags U_ICU_ENTRY_POINT_RENAME(ultag_isPrivateuseValueSubtags)

deps/icu-small/source/common/unicode/uvernum.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
* This value will change in the subsequent releases of ICU
6767
* @stable ICU 2.6
6868
*/
69-
#define U_ICU_VERSION_MINOR_NUM 1
69+
#define U_ICU_VERSION_MINOR_NUM 2
7070

7171
/** The current ICU patchlevel version as an integer.
7272
* This value will change in the subsequent releases of ICU
@@ -139,7 +139,7 @@
139139
* This value will change in the subsequent releases of ICU
140140
* @stable ICU 2.4
141141
*/
142-
#define U_ICU_VERSION "68.1"
142+
#define U_ICU_VERSION "68.2"
143143

144144
/**
145145
* The current ICU library major version number as a string, for library name suffixes.
@@ -158,7 +158,7 @@
158158
/** Data version in ICU4C.
159159
* @internal ICU 4.4 Internal Use Only
160160
**/
161-
#define U_ICU_DATA_VERSION "68.1"
161+
#define U_ICU_DATA_VERSION "68.2"
162162
#endif /* U_HIDE_INTERNAL_API */
163163

164164
/*===========================================================================

0 commit comments

Comments
 (0)