blob: d92347f6f042d8091555f4727f2f13ea5191e519 [file] [log] [blame]
Index: test/cintltst/utexttst.c
===================================================================
--- test/cintltst/utexttst.c (revision 29355)
+++ test/cintltst/utexttst.c (revision 29356)
@@ -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 @@
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 @@
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);
}
{
Index: common/utext.cpp
===================================================================
--- common/utext.cpp (revision 29355)
+++ common/utext.cpp (revision 29356)
@@ -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,6 @@
return 0;
}
- const UChar *s=(const UChar *)ut->context;
int32_t si, di;
int32_t start32;
@@ -2856,8 +2855,8 @@
// 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) {