ICU-5560 Fix UText bug with deep clone buffer pointer handling.
X-SVN-Rev: 20993
This commit is contained in:
parent
acc3a3e636
commit
5a8ece1c9e
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005-2006, International Business Machines
|
* Copyright (C) 2005-2007, International Business Machines
|
||||||
* Corporation and others. All Rights Reserved.
|
* Corporation and others. All Rights Reserved.
|
||||||
*
|
*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
@ -578,8 +578,6 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
|
|||||||
if (spaceRequired>0) {
|
if (spaceRequired>0) {
|
||||||
ut->extraSize = extraSpace;
|
ut->extraSize = extraSpace;
|
||||||
ut->pExtra = &((ExtendedUText *)ut)->extension;
|
ut->pExtra = &((ExtendedUText *)ut)->extension;
|
||||||
uprv_memset(ut->pExtra, 0, extraSpace); // Purify whines about copying untouched extra [buffer]
|
|
||||||
// space when cloning, so init it now.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -611,7 +609,6 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
|
|||||||
} else {
|
} else {
|
||||||
ut->extraSize = extraSpace;
|
ut->extraSize = extraSpace;
|
||||||
ut->flags |= UTEXT_EXTRA_HEAP_ALLOCATED;
|
ut->flags |= UTEXT_EXTRA_HEAP_ALLOCATED;
|
||||||
uprv_memset(ut->pExtra, 0, extraSpace);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -638,6 +635,9 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
|
|||||||
ut->privB = 0;
|
ut->privB = 0;
|
||||||
ut->privC = 0;
|
ut->privC = 0;
|
||||||
ut->privP = NULL;
|
ut->privP = NULL;
|
||||||
|
if (ut->pExtra!=NULL && ut->extraSize>0)
|
||||||
|
uprv_memset(ut->pExtra, 0, ut->extraSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
return ut;
|
return ut;
|
||||||
}
|
}
|
||||||
@ -799,6 +799,7 @@ shallowTextClone(UText * dest, const UText * src, UErrorCode * status) {
|
|||||||
adjustPointer(dest, &dest->p, src);
|
adjustPointer(dest, &dest->p, src);
|
||||||
adjustPointer(dest, &dest->q, src);
|
adjustPointer(dest, &dest->q, src);
|
||||||
adjustPointer(dest, &dest->r, src);
|
adjustPointer(dest, &dest->r, src);
|
||||||
|
adjustPointer(dest, (const void **)&dest->chunkContents, src);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/********************************************************************
|
/********************************************************************
|
||||||
* COPYRIGHT:
|
* COPYRIGHT:
|
||||||
* Copyright (c) 2005-2006, International Business Machines Corporation and
|
* Copyright (c) 2005-2007, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -54,6 +54,8 @@ UTextTest::runIndexedTest(int32_t index, UBool exec,
|
|||||||
if (exec) ErrorTest(); break;
|
if (exec) ErrorTest(); break;
|
||||||
case 2: name = "FreezeTest";
|
case 2: name = "FreezeTest";
|
||||||
if (exec) FreezeTest(); break;
|
if (exec) FreezeTest(); break;
|
||||||
|
case 3: name = "Ticket5560";
|
||||||
|
if (exec) Ticket5560(); break;
|
||||||
default: name = ""; break;
|
default: name = ""; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1350,3 +1352,40 @@ openFragmentedUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
|||||||
return ut;
|
return ut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for Ticket 5560
|
||||||
|
// Clone fails to update chunkContentPointer in the cloned copy.
|
||||||
|
// This is only an issue for UText types that work in a local buffer,
|
||||||
|
// (UTF-8 wrapper, for example)
|
||||||
|
//
|
||||||
|
// The test:
|
||||||
|
// 1. Create an inital UText
|
||||||
|
// 2. Deep clone it. Contents should match original.
|
||||||
|
// 3. Reset original to something different.
|
||||||
|
// 4. Check that clone contents did not change.
|
||||||
|
//
|
||||||
|
void UTextTest::Ticket5560() {
|
||||||
|
char *s1 = "ABCDEF";
|
||||||
|
char *s2 = "123456";
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
|
||||||
|
UText ut1 = UTEXT_INITIALIZER;
|
||||||
|
UText ut2 = UTEXT_INITIALIZER;
|
||||||
|
|
||||||
|
utext_openUTF8(&ut1, s1, -1, &status);
|
||||||
|
UChar c = utext_next32(&ut1);
|
||||||
|
TEST_ASSERT(c == 0x41); // c == 'A'
|
||||||
|
|
||||||
|
utext_clone(&ut2, &ut1, TRUE, FALSE, &status);
|
||||||
|
TEST_SUCCESS(status);
|
||||||
|
c = utext_next32(&ut2);
|
||||||
|
TEST_ASSERT(c == 0x42); // c == 'B'
|
||||||
|
c = utext_next32(&ut1);
|
||||||
|
TEST_ASSERT(c == 0x42); // c == 'B'
|
||||||
|
|
||||||
|
utext_openUTF8(&ut1, s2, -1, &status);
|
||||||
|
c = utext_next32(&ut1);
|
||||||
|
TEST_ASSERT(c == 0x31); // c == '1'
|
||||||
|
c = utext_next32(&ut2);
|
||||||
|
TEST_ASSERT(c == 0x43); // c == 'C'
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/********************************************************************
|
/********************************************************************
|
||||||
* COPYRIGHT:
|
* COPYRIGHT:
|
||||||
* Copyright (c) 2005-2006, International Business Machines Corporation and
|
* Copyright (c) 2005-2007, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -31,6 +31,7 @@ public:
|
|||||||
void TextTest();
|
void TextTest();
|
||||||
void ErrorTest();
|
void ErrorTest();
|
||||||
void FreezeTest();
|
void FreezeTest();
|
||||||
|
void Ticket5560();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct m { // Map between native indices & code points.
|
struct m { // Map between native indices & code points.
|
||||||
|
Loading…
Reference in New Issue
Block a user