diff --git a/icu4c/source/common/uloc.cpp b/icu4c/source/common/uloc.cpp index 3827457e982..6b65c626222 100644 --- a/icu4c/source/common/uloc.cpp +++ b/icu4c/source/common/uloc.cpp @@ -2191,7 +2191,7 @@ uloc_getLCID(const char* localeID) } uloc_getLanguage(localeID, langID, sizeof(langID), &status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) { return 0; } diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 41f6d915e89..2268486a9f1 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -52,6 +52,7 @@ static void TestUnicodeDefines(void); static void TestIsRightToLeft(void); static void TestBadLocaleIDs(void); +static void TestBug20370(void); void PrintDataTable(); @@ -266,6 +267,7 @@ void addLocaleTest(TestNode** root) TESTCASE(TestToUnicodeLocaleType); TESTCASE(TestToLegacyType); TESTCASE(TestBadLocaleIDs); + TESTCASE(TestBug20370); } @@ -6498,3 +6500,13 @@ static void TestBadLocaleIDs() { } } } + +// Test case for ICU-20370. +// The issue shows as an Addresss Sanitizer failure. +static void TestBug20370() { + const char *localeID = "x-privatebutreallylongtagfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar"; + uint32_t lcid = uloc_getLCID(localeID); + if (lcid != 0) { + log_err("FAIL: Expected LCID value of 0 for invalid localeID input."); + } +}