From 606b10c51116e753b4d6d54a913d7482255f2345 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Mon, 10 Feb 2003 22:57:39 +0000 Subject: [PATCH] ICU-2703 fix missing null termination on extract from zero length UnicodeString X-SVN-Rev: 11006 --- icu4c/source/common/unistr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index c97708de96..198b25ce3c 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1514,7 +1514,12 @@ UnicodeString::extract(int32_t start, // just write the NUL if the string length is 0 if(length == 0) { - return u_terminateChars(target, dstSize, 0, &status); + if(dstSize >= 0x80000000) { + // careful: dstSize is unsigned! (0xffffffff means "unlimited") + // make sure that the NUL-termination works (takes int32_t) + dstSize=0x7fffffff; + } + return u_terminateChars(target, dstSize, 0, &status); } // if the codepage is the default, use our cache