mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-17 02:37:25 +00:00
ICU-478 u_uastrncpy fix
X-SVN-Rev: 1694
This commit is contained in:
parent
e6ff764cac
commit
8bc3f0b83b
2 changed files with 20 additions and 9 deletions
|
@ -205,18 +205,26 @@ UChar* u_uastrncpy(UChar *ucs1,
|
|||
const char *s2 ,
|
||||
int32_t n)
|
||||
{
|
||||
UChar *target = ucs1;
|
||||
UConverter *cnv = getDefaultConverter();
|
||||
if(cnv != NULL) {
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
ucnv_toUChars(cnv,
|
||||
ucs1,
|
||||
n,
|
||||
s2,
|
||||
uprv_strlen(s2),
|
||||
&err);
|
||||
ucnv_reset(cnv);
|
||||
ucnv_toUnicode(cnv,
|
||||
&target,
|
||||
ucs1+n,
|
||||
&s2,
|
||||
s2+uprv_strlen(s2),
|
||||
NULL,
|
||||
TRUE,
|
||||
&err);
|
||||
ucnv_reset(cnv); /* be good citizens */
|
||||
releaseDefaultConverter(cnv);
|
||||
if(U_FAILURE(err)) {
|
||||
*ucs1 = 0;
|
||||
if(U_FAILURE(err) && (err != U_INDEX_OUTOFBOUNDS_ERROR) ) {
|
||||
*ucs1 = 0; /* failure */
|
||||
}
|
||||
if(target < (ucs1+n)) { /* Indexoutofbounds isn't an err, just means no termination will happen. */
|
||||
*target = 0; /* terminate */
|
||||
}
|
||||
} else {
|
||||
*ucs1 = 0;
|
||||
|
|
|
@ -696,9 +696,12 @@ void TestStringFunctions()
|
|||
temp[3] = 0xFB;
|
||||
|
||||
u_uastrncpy(temp, "abcabcabc", 3);
|
||||
if(u_strcmp(uchars, temp) != 0)
|
||||
if(u_strncmp(uchars, temp, 3) != 0)
|
||||
log_err("There is an error in u_uastrncpy() Expected %s Got %s\n", austrdup(uchars), austrdup(temp));
|
||||
}
|
||||
if(temp[3] != 0xFB) {
|
||||
log_err("u_austrncpy wrote past it's bounds. Expected undisturbed byte at 3\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue