diff --git a/icu4c/source/i18n/translit.cpp b/icu4c/source/i18n/translit.cpp index f5e8a56e722..a1f4813083a 100644 --- a/icu4c/source/i18n/translit.cpp +++ b/icu4c/source/i18n/translit.cpp @@ -129,7 +129,11 @@ inline UBool positionIsValid(UTransPosition& index, int32_t len) { Transliterator::Transliterator(const UnicodeString& theID, UnicodeFilter* adoptedFilter) : UObject(), ID(theID), filter(adoptedFilter), - maximumContextLength(0) {} + maximumContextLength(0) { + + // NUL-terminate the ID string + ID.getTerminatedBuffer(); +} /** * Destructor. @@ -144,6 +148,10 @@ Transliterator::~Transliterator() { Transliterator::Transliterator(const Transliterator& other) : UObject(other), ID(other.ID), filter(0), maximumContextLength(other.maximumContextLength) { + + // NUL-terminate the ID string + ID.getTerminatedBuffer(); + if (other.filter != 0) { // We own the filter, so we must have our own copy filter = (UnicodeFilter*) other.filter->clone(); @@ -155,6 +163,9 @@ Transliterator::Transliterator(const Transliterator& other) : */ Transliterator& Transliterator::operator=(const Transliterator& other) { ID = other.ID; + // NUL-terminate the ID string + ID.getTerminatedBuffer(); + maximumContextLength = other.maximumContextLength; adoptFilter((other.filter == 0) ? 0 : (UnicodeFilter*) other.filter->clone()); return *this;