ICU-8267 ucstrTextExtract should use text pointer & offset for chunk, as set by ucstrTextAccess

X-SVN-Rev: 29356
This commit is contained in:
Peter Edberg 2011-01-25 03:25:24 +00:00
parent d2ef184687
commit 5224f25511
2 changed files with 23 additions and 5 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2005-2010, International Business Machines
* Copyright (C) 2005-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -2846,7 +2846,7 @@ ucstrTextExtract(UText *ut,
return 0;
}
const UChar *s=(const UChar *)ut->context;
//const UChar *s=(const UChar *)ut->context;
int32_t si, di;
int32_t start32;
@ -2856,8 +2856,8 @@ ucstrTextExtract(UText *ut,
// Pins 'start' to the length of the string, if it came in out-of-bounds.
// Snaps 'start' to the beginning of a code point.
ucstrTextAccess(ut, start, TRUE);
U_ASSERT(start <= INT32_MAX);
start32 = (int32_t)start;
const UChar *s=ut->chunkContents;
start32 = ut->chunkOffset;
int32_t strLength=(int32_t)ut->a;
if (strLength >= 0) {

View file

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2005-2009, International Business Machines Corporation and
* Copyright (c) 2005-2011, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/*
@ -210,6 +210,10 @@ static void TestAPI(void) {
UChar uString[] = {0x41, 0x42, 0x43, 0};
UChar buf[100];
int32_t i;
/* Test pinning of input bounds */
UChar uString2[] = {0x41, 0x42, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4A, 0};
UChar * uString2Ptr = uString2 + 5;
status = U_ZERO_ERROR;
uta = utext_openUChars(NULL, uString, -1, &status);
@ -228,6 +232,20 @@ static void TestAPI(void) {
i = u_strcmp(uString, buf);
TEST_ASSERT(i == 0);
utext_close(uta);
/* Test pinning of input bounds */
status = U_ZERO_ERROR;
uta = utext_openUChars(NULL, uString2Ptr, -1, &status);
TEST_SUCCESS(status);
status = U_ZERO_ERROR;
memset(buf, 0, sizeof(buf));
i = utext_extract(uta, -3, 20, buf, 100, &status);
TEST_SUCCESS(status);
TEST_ASSERT(i == u_strlen(uString2Ptr));
i = u_strcmp(uString2Ptr, buf);
TEST_ASSERT(i == 0);
utext_close(uta);
}
{