diff --git a/icu4c/source/common/ulocale.cpp b/icu4c/source/common/ulocale.cpp index aaa17954a393..f2f81bc97109 100644 --- a/icu4c/source/common/ulocale.cpp +++ b/icu4c/source/common/ulocale.cpp @@ -21,7 +21,10 @@ U_NAMESPACE_USE ULocale* ulocale_openForLocaleID(const char* localeID, int32_t length, UErrorCode* err) { if (U_FAILURE(*err)) { return nullptr; } - CharString str(length < 0 ? StringPiece(localeID) : StringPiece(localeID, length), *err); + if (length < 0) { + return EXTERNAL(icu::Locale::createFromName(localeID).clone()); + } + CharString str(localeID, length, *err); // Make a NUL terminated copy. if (U_FAILURE(*err)) { return nullptr; } return EXTERNAL(icu::Locale::createFromName(str.data()).clone()); }