ICU-10371 fix assertion in u_strFromUTF8()/u_strFromUTF8WithSub() code

X-SVN-Rev: 34279
This commit is contained in:
Markus Scherer 2013-09-12 00:02:41 +00:00
parent caf4feecef
commit fbb5f5ba1f
2 changed files with 17 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 2001-2012, International Business Machines
* Copyright (C) 2001-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -34,6 +34,8 @@
#include "ustr_imp.h"
#include "uassert.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
U_CAPI UChar* U_EXPORT2
u_strFromUTF32WithSub(UChar *dest,
int32_t destCapacity,
@ -381,7 +383,7 @@ utf8_nextCharSafeBodyPointer(const uint8_t **ps, const uint8_t *limit, UChar32 c
/* correct sequence - all trail bytes have (b7..b6)==(10)? */
/* illegal is also set if count>=4 */
U_ASSERT(count<sizeof(utf8_minLegal)/sizeof(utf8_minLegal[0]));
U_ASSERT(illegal || count<LENGTHOF(utf8_minLegal));
if(illegal || c<utf8_minLegal[count] || U_IS_SURROGATE(c)) {
/* error handling */
/* don't go beyond this sequence */

View File

@ -846,6 +846,19 @@ static void Test_UChar_UTF8_API(void){
log_err("error: u_strToUTF8WithSub(no subchar) failed\n");
}
}
{
/*
* Test with an illegal lead byte that would be followed by more than 3 trail bytes.
* See ticket #10371.
*/
static const char src[1]={ 0xf8 };
UChar out16[10];
err=U_ZERO_ERROR;
u_strFromUTF8(out16, LENGTHOF(out16), NULL, src, 1, &err);
if(err!=U_INVALID_CHAR_FOUND) {
log_err("error: u_strFromUTF8(5-byte lead byte) failed\n");
}
}
}
/* compare if two strings are equal, but match 0xfffd in the second string with anything in the first */