mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-7500 fix uloc_getDisplayName incorrect length
X-SVN-Rev: 27774
This commit is contained in:
parent
d159b81c9f
commit
809ac514dc
3 changed files with 28 additions and 6 deletions
|
@ -662,7 +662,7 @@ uloc_getDisplayName(const char *locale,
|
|||
if ( p0 != NULL && p1 != NULL ) { /* The pattern is well formed */
|
||||
if ( dest ) {
|
||||
int32_t destLen = 0;
|
||||
UChar *result = (UChar *)uprv_malloc((length+1)*sizeof(UChar));
|
||||
UChar *result = (UChar *)uprv_malloc((length+1)*sizeof(UChar));
|
||||
UChar *upos = (UChar *)dispLocPattern;
|
||||
u_strcpy(result,dest);
|
||||
dest[0] = 0;
|
||||
|
@ -684,7 +684,8 @@ uloc_getDisplayName(const char *locale,
|
|||
destLen++;
|
||||
dest[destLen] = 0; /* Null terminate */
|
||||
}
|
||||
}
|
||||
}
|
||||
length = destLen;
|
||||
uprv_free(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,6 +240,7 @@ void addLocaleTest(TestNode** root)
|
|||
TESTCASE(TestLikelySubtags);
|
||||
TESTCASE(TestToLanguageTag);
|
||||
TESTCASE(TestForLanguageTag);
|
||||
TESTCASE(TestTrailingNull);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2119,9 +2120,28 @@ static void TestGetBaseName(void) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void TestTrailingNull(void) {
|
||||
const char* localeId = "zh_Hans";
|
||||
UChar buffer[128]; /* sufficient for this test */
|
||||
int32_t len;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
int i;
|
||||
|
||||
len = uloc_getDisplayName(localeId, localeId, buffer, 128, &status);
|
||||
if (len > 128) {
|
||||
log_err("buffer too small");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (buffer[i] == 0) {
|
||||
log_err("name contained null");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Jitterbug 4115 */
|
||||
static void TestDisplayNameWarning(void) {
|
||||
|
@ -5536,4 +5556,3 @@ static void TestForLanguageTag(void) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/********************************************************************************
|
||||
|
@ -89,6 +89,8 @@ static void TestDisplayNames(void);
|
|||
|
||||
static void TestGetBaseName(void);
|
||||
|
||||
static void TestTrailingNull(void);
|
||||
|
||||
static void TestGetLocale(void);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue