diff --git a/icu4c/source/i18n/coleitr.cpp b/icu4c/source/i18n/coleitr.cpp index 4b113a284d..eef528979a 100644 --- a/icu4c/source/i18n/coleitr.cpp +++ b/icu4c/source/i18n/coleitr.cpp @@ -220,14 +220,21 @@ CollationElementIterator::CollationElementIterator( return; int32_t length = sourceText.length(); - UChar *string = (UChar *)uprv_malloc(sizeof(UChar) * (length + 1)); - /* - Using this constructor will prevent buffer from being removed when - string gets removed - */ - sourceText.extract(0, length, string); - // null terminate it - string[length] = 0; + UChar *string = NULL; + + if (length > 0) { + string = (UChar *)uprv_malloc(sizeof(UChar) * length); + /* + Using this constructor will prevent buffer from being removed when + string gets removed + */ + sourceText.extract(0, length, string); + } + else { + string = (UChar *)uprv_malloc(sizeof(UChar)); + // null terminate it + *string = 0; + } m_data_ = ucol_openElements(order->ucollator, string, length, &status); m_data_->isWritable = TRUE;